Q:

Write a NumPy program to change the sign of a given array to that of a given array, element-wise

0

Write a NumPy program to change the sign of a given array to that of a given array, element-wise.

All Answers

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

import numpy as np
x1 = np.array([-1, 0, 1, 2])
print("Original array: ")
print(x1)
x2 = -2.1
print("\nSign of x1 to that of x2, element-wise:")
print(np.copysign(x1, x2))

Sample Output:

Original array: 
[-1  0  1  2]

Sign of x1 to that of x2, element-wise:
[-1.  0.  1.  2.]

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