Display the Numerical positive and negative element-wise in Numpy

NumpyServer Side ProgrammingProgramming

To display the Numerical negative, use the np.negative() method in Python Numpy. The 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 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 library −

import numpy as np

Create an array −

arr = np.array([-3, 6, 9, -12, -24, 30, -55])

Display the array −

print("Array...\n", arr)

Get the type of the array −

print("\nOur Array type...\n", arr.dtype)

Get the dimensions of the Array −

print("\nOur Array Dimension...\n",arr.ndim)

Get the shape of the Array −

print("\nOur Array Shape...\n",arr.shape)

To display the Numerical positive, use the np.positive() method in Python Numpy −

print("\nNumerical positive...\n",np.positive(arr))

To display the Numerical negative, use the np.negative() method in Python Numpy −

print("\nNumerical negative...\n",np.negative(arr))

Example

import numpy as np

# Create an array
arr = np.array([-3, 6, 9, -12, -24, 30, -55])

# Display the array
print("Array...\n", arr)

# Get the type of the array
print("\nOur Array type...\n", arr.dtype)

# Get the dimensions of the Array
print("\nOur Array Dimension...\n",arr.ndim)

# Get the shape of the Array
print("\nOur Array Shape...\n",arr.shape)

# To display the Numerical positive, use the np.positive() method in Python Numpy
print("\nNumerical positive...\n",np.positive(arr))

# To display the Numerical negative, use the np.negative() method in Python Numpy
print("\nNumerical negative...\n",np.negative(arr))

Output

Array...
[ -3 6 9 -12 -24 30 -55]

Our Array type...
int64

Our Array Dimension...
1

Our Array Shape...
(7,)

Numerical positive...
[ -3 6 9 -12 -24 30 -55]

Numerical negative...
[ 3 -6 -9 12 24 -30 55]
raja
Updated on 07-Feb-2022 13:03:20

Advertisements