
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Return the square of the complex-value input in Python
To return the element-wise square of the array input, use the numpy.square() method in Python. The method returns the element-wise x*x, of the same shape and dtype as x. This is a scalar if x is a scalar. The 1st parameter, x is the input data. The 2nd parameter, out is 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 the number of outputs.
The 3rd parameter, where, this condition is broadcast over the input. At locations where the condition is True, the out array will be set to the ufunc result. Elsewhere, the out array will retain its original value. Note that if an uninitialized out array is created via the default out=None, locations within it where the condition is False will remain uninitialized.
Steps
At first, import the required libraries-
import numpy as np
Creating a numpy array using the array() method. We have added elements of complex type −
arr = np.array([[3 + 4j, 5 + 7j], [2 + 6j, -2j]])
Display the array −
print("Our Array...\n",arr)
Check the Dimensions −
print("\nDimensions of our Array...\n",arr.ndim)
Get the Datatype −
print("\nDatatype of our Array object...\n",arr.dtype)
To return the element-wise square of the array input, use the numpy.square() method in Python. The method returns the element-wise x*x, of the same shape and dtype as x. This is a scalar if x is a scalar −
print("\nResult...\n",np.square(arr))
Example
import numpy as np # Creating a numpy array using the array() method # We have added elements of complex type arr = np.array([[3 + 4j, 5 + 7j], [2 + 6j, -2j]]) # Display the array print("Our Array...\n",arr) # Check the Dimensions print("\nDimensions of our Array...\n",arr.ndim) # Get the Datatype print("\nDatatype of our Array object...\n",arr.dtype) # To return the element-wise square of the array input, use the numpy.square() method in Python print("\nResult...\n",np.square(arr))
Output
Our Array... [[ 3.+4.j 5.+7.j] [ 2.+6.j -0.-2.j]] Dimensions of our Array... 2 Datatype of our Array object... complex128 Result... [[ -7.+24.j -24.+70.j] [-32.+24.j -4. +0.j]]
- Related Articles
- Return the base 2 logarithm for complex value input in Python
- Return the element-wise square of the array input in Python
- Return the angle of the complex argument in Python
- Return the imaginary part of the complex argument in Python
- Return the real part of the complex argument in Python
- Return the angle of the complex argument in degrees in Python
- Return the angle of the complex argument in radians in Python
- Return the element-wise square-root of a complex type array in Numpy
- Return the result of the power to which the input value is raised with scimath in Python
- Compute the square root of complex inputs with scimath in Python
- Compute the Natural logarithm for complex-valued input in Python
- Return the result of the negative power to which the input value is raised with scimath in Python
- Return the result of the power to which the negative input value is raised with scimath in Python
- Return the base 2 logarithm of the input array in Python
- Compute the square root of input with emath in Python
