Q:

Write a NumPy program to calculate the difference between the maximum and the minimum values of a given array along the second axis

0

Write a NumPy program to calculate the difference between the maximum and the minimum values of a given array along the second axis.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy as np
x = np.arange(12).reshape((2, 6))
print("\nOriginal array:")
print(x)
r1 = np.ptp(x, 1)
r2 = np.amax(x, 1) - np.amin(x, 1)
assert np.allclose(r1, r2)
print("\nDifference between the maximum and the minimum values of the said array:")
print(r1)

Sample Output:

Original array:
[[ 0  1  2  3  4  5]
 [ 6  7  8  9 10 11]]

Difference between the maximum and the minimum values of the said array:
[5 5]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now