Coggle requires JavaScript to display documents.
a = np.array([[-2.5, 3.1, 7], [10, 11, 12]]) np.square(a)
print("Original ndarray") print(a) for func in (np.abs, np.sqrt, np.exp, np.log, np.sign, np.ceil, np.modf, np.isnan, np.cos): print("\n", func.__name__) print(func(a))
h = np.arange(5).reshape(1, 1, 5) h
h + [10, 20, 30, 40, 50]
k = np.arange(6).reshape(2, 3) k
k + [[100], [200]]
k + [100, 200, 300]
k + 1000
try: k + [33, 44] except ValueError as e: print(e)
k1 = np.arange(0, 5, dtype=np.uint8) print(k1.dtype, k1)
k2 = k1 + np.array([5, 6, 7, 8, 9], dtype=np.int8) print(k2.dtype, k2)
k3 = k1 + 1.5 print(k3.dtype, k3)
m = np.array([20, -5, 30, 40]) m < [15, 16, 35, 36]
m < 25 # equivalent to m < [25, 25, 25, 25]
m[m < 25]
a = np.array([[-2.5, 3.1, 7], [10, 11, 12]]) print(a) print("mean =", a.mean())
for func in (a.min, a.max, a.sum, a.prod, a.std, a.var): print(func.__name__, "=", func())
c = np.arange(24).reshape(2,3,4) c
c.sum(axis=0) # sum across matrices
c.sum(axis=1) # sum across rows
c.sum(axis=(0,2)) # sum across matrices and columns
0+1+2+3 + 12+13+14+15, 4+5+6+7 + 16+17+18+19, 8+9+10+11 + 20+21+22+23
a = np.array([1, -2, 3, 4]) b = np.array([2, 8, -1, 7]) np.add(a, b) # equivalent to a + b
np.greater(a, b) # equivalent to a > b
np.maximum(a, b)
np.copysign(a, b)