How to find the square of all elements of a list or a Numpy array?

The numpy.square() function takes a NumPy array or list as input and calculates the square of each element in the array. It returns a new array with the same shape as the input array, containing the squared values of the elements. For example, if the input array is [1, 2, 3], the output array will be [1, 4, 9]. This function is useful for performing mathematical operations on arrays or lists of data.