9951 explained code solutions for 126 technologies


python-numpyCalculate x^2 (square) for Numpy array


import numpy as np
arr = np.array([[1, 2], [3, 4]])
arr = np.square(arr)ctrl + c
import numpy as np

load Numpy module for Python

np.array

declare Numpy array

[[1, 2], [3, 4]]

sample array data

np.square

calculates squares for each value in a given array

arr

array to calculate squares for values of