NumPy is a Python library that has various functions to perform calculations on the arrays of numeric data. One of these is the square()
function.
numpy.square()
functionThe numpy.square()
function computes the square value of each array element.
numpy.square(arr)
arr
: This represents the input array whose element we need to square.The following code shows how to use the numpy.square()
in Python:
# import numpyimport numpy as np# create a listmy_list = [24,8,3,4,34,8]# convert the list to numpy arraynp_list = np.array(my_list)# compute the square of each element and store itnp_list_square = np.square(np_list)print(np_list_square)
numpy
library.my_list
.np_list
.np.square()
to compute the square of each element in the np_list
.