In this python numpy program, we will print squares of all the elements of an array using NumPy.
Steps to solve the program
- Import the numpy library as np.
- Create an array using np.array().
- Use np.square() to get the squares of all the elements in the given array.
- Print the output.
import numpy as np
x = np.array([2,6,3,1])
print("Sqaure of every element in the arrary: ",np.square(x))
Output :
Sqaure of every element in the arrary: [ 4 36 9 1]