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 numpy import numpy as np # create a list my_list = [24,8,3,4,34,8] # convert the list to numpy array np_list = np.array(my_list) # compute the square of each element and store it np_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
.RELATED TAGS
CONTRIBUTOR
View all Courses