square(x, out=None, **kwargs)

Return the element-wise square of the input.

  • x (ndarray or scalar) – The values whose squares are required.

  • out (ndarray or None, optional) – A location into which the result is stored. If provided, it must have the same shape as the input. If not provided or None, a freshly-allocated array is returned.


y – Output array is same shape and type as x. This is a scalar if x is a scalar.

Return type

ndarray or scalar


>>> np.square(2.)
>>> x = np.array([1, 2., -1])
>>> np.square(x)
array([1., 4., 1.])


The output ndarray has the same device as the input ndarray. This function differs from the original numpy.square in the following aspects:

  • Only support ndarray and scalar now.

  • where argument is not supported.

  • Complex input is not supported.