In [1]:
import numpy as np
In [2]:
a = np.arange(12).reshape(3, 4)
print(a)
In [3]:
b = np.arange(-5, 7).reshape(3, 4)
print(b)
In [4]:
a_copysign = np.copysign(a, b)
print(a_copysign)
In [5]:
print(a_copysign.dtype)
In [6]:
print(np.copysign(10, -5))
In [7]:
print(type(np.copysign(10, -5)))
In [8]:
print(a)
In [9]:
b_small = np.array([-100, -100, 100, 100])
print(b_small)
In [10]:
print(a + b_small)
In [11]:
print(np.copysign(a, b_small))
In [12]:
b_mismatch = np.array([-100, -100, 100])
print(b_mismatch)
In [13]:
# print(np.copysign(a, b_mismatch))
# ValueError: operands could not be broadcast together with shapes (3,4) (3,)
In [14]:
print(np.copysign(b, -10))
In [15]:
print(np.abs(b) * -1)
In [16]:
print(np.abs(b) * -1.0)
In [17]:
a_special = np.array([0.0, -0.0, np.inf, -np.inf, np.nan])
print(a_special)
In [18]:
print(np.copysign(a_special, 1))
In [19]:
print(np.copysign(a_special, -1))
In [20]:
print(np.copysign([10, 10, 10, 10, 10], a_special))
In [21]:
print(np.copysign([-10, -10, -10, -10, -10], a_special))
In [22]:
print(np.copysign(10, 0))
In [23]:
print(np.copysign(0, 10))
In [24]:
print(np.copysign(0, -10))
In [25]:
a_complex = np.array([10 + 10j, -10 + 10j])
print(a_complex)
In [26]:
# print(np.copysign(a_complex, 1))
# TypeError: ufunc 'copysign' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
In [27]:
# print(np.copysign([1, 1], a_complex))
# TypeError: ufunc 'copysign' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''