How to calculate the difference between maximum and minimum of NumPy 2d array columns in Python

2 Answers

0 votes
import numpy as np

arr2d = np.array([[4, 8, 2,  5], 
                  [6, 9, 7,  3], 
                  [1, 0, 5, 11]])

print(np.ptp(arr2d, axis=0))





'''
run:

[5 9 5 8]

'''

 



answered Mar 26, 2023 by avibootz
0 votes
import numpy as np

arr2d = np.array([[4, 8, 2,  5], 
                  [6, 9, 7,  3], 
                  [1, 0, 5, 11]])

print(np.max(arr2d, axis=0) - np.min(arr2d, axis=0))





'''
run:

[5 9 5 8]

'''

 



answered Mar 26, 2023 by avibootz
...