In [1]:
import numpy as np
In [2]:
a = np.arange(12).reshape(3, 4)
print(a)
In [3]:
b = np.arange(12).reshape(4, 3).T
print(b)
In [4]:
a_compare = a < b
print(a_compare)
In [5]:
print(type(a_compare))
In [6]:
print(a_compare.dtype)
In [7]:
print(a > b)
In [8]:
print(a <= b)
In [9]:
print(a >= b)
In [10]:
print(a == b)
In [11]:
print(a != b)
In [12]:
b_float = b.astype(float)
print(b_float)
In [13]:
print(b_float.dtype)
In [14]:
print(a == b_float)
In [15]:
b_1d = np.arange(4, 8)
print(b_1d)
In [16]:
print(a < b_1d)
In [17]:
print(a < 6)
In [18]:
print(a % 2)
In [19]:
print(a % 2 == 0)
In [20]:
print(np.count_nonzero(a < 6))
In [21]:
print(np.all(a < 6))
In [22]:
print(np.all(a < 6, axis=1))
In [23]:
print(np.any(a < 6))
In [24]:
print(np.any(a < 6, axis=1))
In [25]:
a_nan = np.array([0, 1, np.nan])
print(a_nan)
In [26]:
print(a_nan == np.nan)
In [27]:
print(np.isnan(a_nan))
In [28]:
print(a_nan > 0)
In [29]:
a_nan_only = np.array([np.nan])
print(a_nan_only)
In [30]:
print(a_nan_only > 0)
In [31]:
print(np.nan > 0)
In [32]:
x = 6
In [33]:
print(4 < x < 8)
In [34]:
# print(4 < a < 8)
# ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
In [35]:
print((a > 4) & (a < 8))
In [36]:
# print((a > 4) and (a < 8))
# ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
In [37]:
# print(a > 4 & a < 8)
# ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
In [38]:
x = 6
y = 6
z = 6
In [39]:
print(x == y == z)
In [40]:
c = np.zeros((3, 4), int)
print(c)
In [41]:
# print(a == b == c)
# ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
In [42]:
print((a == b) & (b == c))