Q:

Write a NumPy program to check element-wise True/False of a given array where signbit is set

0

Write a NumPy program to check element-wise True/False of a given array where signbit is set.

Sample array: [-4, -3, -2, -1, 0, 1, 2, 3, 4]

All Answers

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

import numpy as np
x = np.array([-4, -3, -2, -1, 0, 1, 2, 3, 4])
print("Original array: ")
print(x)
r1 = np.signbit(x)
r2 = x < 0
assert np.array_equiv(r1, r2)
print(r1)

Sample Output:

Original array: 
[-4 -3 -2 -1  0  1  2  3  4]
[ True  True  True  True False False False False False]

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