Instagram
youtube
Facebook
Twitter

Compute Absolute Values of NumPy Array

A Compute Absolute Values of NumPy Array?
Code Explanation:
Library Import:
numpy is imported as np to use mathematical and array functions.
Array Creation: A NumPy array arr is created with both negative and positive values.
Absolute Function: np.abs(arr) computes the absolute (positive) values of all elements in the array.
Store Result: The absolute values are stored in the variable abs_arr.
Display Output: print(abs_arr) prints the array with absolute values: [1 2 3].

 

Program:

import numpy as np

arr = np.array([-1, -2, 3])

abs_arr = np.abs(arr)

print(abs_arr)