You can check the execution time to get clear picture of it

In [2]: import numpy as np
In [3]: A = np.array([[2, 2],[2, 2]])
In [7]: %timeit np.square(A)
1000000 loops, best of 3: 923 ns per loop
In [8]: %timeit A ** 2
1000000 loops, best of 3: 668 ns per loop
Answer from saimadhu.polamuri on Stack Overflow
🌐
Medium
medium.com › @amit25173 › what-is-numpy-square-and-when-to-use-it-20528b14ac86
What is numpy.square and When to Use It? | by Amit Yadav | Medium
February 9, 2025 - The square of -2 is 4, just like the square of 2 is 4. No need for any additional checks or conditions—numpy.square has your back.
🌐
Netalith
netalith.com › blogs › tutorial › numpysquare-in-python
numpy square: Fast, Accurate Array Squaring Examples & Tips | Netalith
February 22, 2026 - Guide and examples for using numpy.square to compute elementwise squares across integers, floats, complex numbers and 2D arrays, including dtype behavior and differences vs **2.
🌐
IncludeHelp
includehelp.com › python › numpy-square-method-vs-operator.aspx
Python - numpy.square() Method vs ** Operator
December 27, 2023 - The numpy.square() returns the element-wise square of the input. On the other hand, the ** operator is another method to find the square of a given number. While applying this method, the exponent operator returns the exponential power resulting in the square of the number.
🌐
Stack Overflow
stackoverflow.com › questions › 70585909 › python-precision-of-numpy-square-vs
Python: Precision of numpy.square vs ** - Stack Overflow
This is not the case for a ** 2 unless the absolute value of the exponent is less than 53 (i.e., unless the exponent is less than the precision of the double-precision representation). In general, it is best to avoid powers (**) and use numpy.square() instead.
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.square.html
numpy.square — NumPy v2.2 Manual
numpy.square(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature]) = <ufunc 'square'># Return the element-wise square of the input. Parameters: xarray_like · Input data. outndarray, None, or tuple of ndarray and None, optional ·
🌐
Medium
medium.com › @whyamit404 › different-ways-to-perform-element-wise-square-in-numpy-5ac1aa754b05
Different Ways to Perform Element-wise Square in NumPy | by whyamit404 | Medium
February 27, 2025 - Let me walk you through the different methods, each with its own charm. ... This is probably the simplest method. If you know how to square a number like 2 ** 2 = 4, you already know the basics.
🌐
DigitalOcean
digitalocean.com › community › tutorials › numpy-square-in-python
numpy.square() in Python | DigitalOcean
Technical tutorials, Q&A, events — This is an inclusive place where developers can find or lend support and discover new ways to contribute to the community.
Find elsewhere
🌐
NumPy
numpy.org › doc › 2.4 › reference › generated › numpy.square.html
numpy.square — NumPy v2.4 Manual
Return the element-wise square of the input · A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned. A tuple (possible only as a keyword argument) must have length equal to ...
🌐
NumPy
numpy.org › doc › 2.0 › reference › generated › numpy.square.html
numpy.square — NumPy v2.0 Manual
Return the element-wise square of the input · A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned. A tuple (possible only as a keyword argument) must have length equal to ...
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.square.html
numpy.square — NumPy v2.6.dev0 Manual
Return the element-wise square of the input · A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned. A tuple (possible only as a keyword argument) must have length equal to ...
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.square.html
numpy.square — NumPy v2.5 Manual
Return the element-wise square of the input · A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned. A tuple (possible only as a keyword argument) must have length equal to ...
🌐
Codecademy
codecademy.com › docs › python:numpy › math methods › .square()
Python:NumPy | Math Methods | .square() | Codecademy
December 20, 2024 - If the condition is True at a particular index, the corresponding element in the array will be squared. If the condition is False, the element will remain unchanged. For instance: import numpy as np · array = np.array([1, 2, 3, 4, 5]) conditions = np.array([False, True, True, False, True]) result = np.square(array, where=conditions) print(result) Copy to clipboard ·
🌐
SciPy
docs.scipy.org › doc › numpy-1.15.0 › reference › generated › numpy.square.html
numpy.square — NumPy v1.15 Manual
Return the element-wise square of the input · A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned. A tuple (possible only as a keyword argument) must have length equal to ...
🌐
GeeksforGeeks
geeksforgeeks.org › numpy-square-python
numpy.square() in Python - GeeksforGeeks
February 23, 2023 - numpy.sqrt() in Python is a function from the NumPy library used to compute the square root of each element in an array or a single number. It returns a new array of the same shape with the square roots of the input values. The function handles both positive and negative numbers, returning NaN for n · 2 min read numpy.std() in Python ·
Top answer
1 of 3
88

The fastest way is to do a*a or a**2 or np.square(a) whereas np.power(a, 2) showed to be considerably slower.

np.power() allows you to use different exponents for each element if instead of 2 you pass another array of exponents. From the comments of @GarethRees I just learned that this function will give you different results than a**2 or a*a, which become important in cases where you have small tolerances.

I've timed some examples using NumPy 1.9.0 MKL 64 bit, and the results are shown below:

In [29]: a = np.random.random((1000, 1000))

In [30]: timeit a*a
100 loops, best of 3: 2.78 ms per loop

In [31]: timeit a**2
100 loops, best of 3: 2.77 ms per loop

In [32]: timeit np.power(a, 2)
10 loops, best of 3: 71.3 ms per loop
2 of 3
3
>>> import numpy
>>> print numpy.power.__doc__

power(x1, x2[, out])

First array elements raised to powers from second array, element-wise.

Raise each base in `x1` to the positionally-corresponding power in
`x2`.  `x1` and `x2` must be broadcastable to the same shape.

Parameters
----------
x1 : array_like
    The bases.
x2 : array_like
    The exponents.

Returns
-------
y : ndarray
    The bases in `x1` raised to the exponents in `x2`.

Examples
--------
Cube each element in a list.

>>> x1 = range(6)
>>> x1
[0, 1, 2, 3, 4, 5]
>>> np.power(x1, 3)
array([  0,   1,   8,  27,  64, 125])

Raise the bases to different exponents.

>>> x2 = [1.0, 2.0, 3.0, 3.0, 2.0, 1.0]
>>> np.power(x1, x2)
array([  0.,   1.,   8.,  27.,  16.,   5.])

The effect of broadcasting.

>>> x2 = np.array([[1, 2, 3, 3, 2, 1], [1, 2, 3, 3, 2, 1]])
>>> x2
array([[1, 2, 3, 3, 2, 1],
       [1, 2, 3, 3, 2, 1]])
>>> np.power(x1, x2)
array([[ 0,  1,  8, 27, 16,  5],
       [ 0,  1,  8, 27, 16,  5]])
>>>

Precision

As per the discussed observation on numerical precision as per @GarethRees objection in comments:

>>> a = numpy.ones( (3,3), dtype = numpy.float96 ) # yields exact output
>>> a[0,0] = 0.46002700024131926
>>> a
array([[ 0.460027,  1.0,  1.0],
       [ 1.0,  1.0,  1.0],
       [ 1.0,  1.0,  1.0]], dtype=float96)
>>> b = numpy.power( a, 2 )
>>> b
array([[ 0.21162484,  1.0,  1.0],
       [ 1.0,  1.0,  1.0],
       [ 1.0,  1.0,  1.0]], dtype=float96)

>>> a.dtype
dtype('float96')
>>> a[0,0]
0.46002700024131926
>>> b[0,0]
0.21162484095102677

>>> print b[0,0]
0.211624840951
>>> print a[0,0]
0.460027000241

Performance

>>> c    = numpy.random.random( ( 1000, 1000 ) ).astype( numpy.float96 )

>>> import zmq
>>> aClk = zmq.Stopwatch()

>>> aClk.start(), c**2, aClk.stop()
(None, array([[ ...]], dtype=float96), 5663L)                #   5 663 [usec]

>>> aClk.start(), c*c, aClk.stop()
(None, array([[ ...]], dtype=float96), 6395L)                #   6 395 [usec]

>>> aClk.start(), c[:,:]*c[:,:], aClk.stop()
(None, array([[ ...]], dtype=float96), 6930L)                #   6 930 [usec]

>>> aClk.start(), c[:,:]**2, aClk.stop()
(None, array([[ ...]], dtype=float96), 6285L)                #   6 285 [usec]

>>> aClk.start(), numpy.power( c, 2 ), aClk.stop()
(None, array([[ ... ]], dtype=float96), 384515L)             # 384 515 [usec]
🌐
DataCamp
datacamp.com › tutorial › python-square
How to Square a Number in Python: Basic and Advanced Methods | DataCamp
June 3, 2026 - The simplest way to square a number is using the exponent operator: 5 ** 2. It's built-in, requires no imports, and clearly expresses the intent of raising to a power. The pow() function is an in-built Python function to square a number.
🌐
TutorialsPoint
tutorialspoint.com › return-the-element-wise-square-of-the-array-input-in-python
NumPy square() Function
February 25, 2022 - The NumPy square() function is used to compute the square of all elements in an input array. It calculates x2 for each element x in the array. This function can be applied to scalars, lists, or NumPy arrays and will return an array of the same shape
🌐
NumPy
numpy.org › doc › 2.3 › reference › generated › numpy.square.html
numpy.square — NumPy v2.3 Manual
Return the element-wise square of the input · A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned. A tuple (possible only as a keyword argument) must have length equal to ...
🌐
SciPy
docs.scipy.org › doc › numpy-1.14.0 › reference › generated › numpy.square.html
numpy.square — NumPy v1.14 Manual
January 8, 2018 - numpy.square(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'square'>¶ · Return the element-wise square of the input. See also · numpy.linalg.matrix_power, sqrt, power · Examples · >>> np.square([-1j, 1]) array([-1.-0.j, 1.+0.j]) numpy.cbrt ·