import numpy as np
x = np.array([[1,2,3],[4,5,6],[1,2,3]])
x.flatten()
array([1, 2, 3, 4, 5, 6, 1, 2, 3])
import numpy as np
x = np.array([[1,2,3],[4,5,6],[1,2,3]])
x.ravel()
array([1, 2, 3, 4, 5, 6, 1, 2, 3])
x = np.array([[1,2,3],[2,3,4]])
print(np.prod(x))
print(np.prod(x,axis=1))
np.prod(x,axis=0)
144
[ 6 24]
array([ 2, 6, 12])
import numpy as np
x = np.array([[1,2,3],[-3,2,4],[5,-2,9]])
print(x)
y1 = np.maximum(0,x)
print(y1)
y2 = np.minimum(0,x)
print(y2)
x1 = x.copy()
print(x1)
x1[x1 < 0] = 0
print(x1)
x2 = x.copy()
x2[x2 > 0] = 0
print(x2)
[[ 1 2 3]
[-3 2 4]
[ 5 -2 9]]
[[1 2 3]
[0 2 4]
[5 0 9]]
[[ 0 0 0]
[-3 0 0]
[ 0 -2 0]]
[[ 1 2 3]
[-3 2 4]
[ 5 -2 9]]
[[1 2 3]
[0 2 4]
[5 0 9]]
[[ 0 0 0]
[-3 0 0]
[ 0 -2 0]]
import numpy as np
x = np.array([[1,2,3],[-3,2,4],[5,-2,9]])
x
x1 = x.copy()
x1[x1 > 0] = 0
x1
x
x2 = x
x2
x2[x2>0] = 0
x2
x
x = np.array([[1,2,3],[-3,2,4],[5,-2,9]])
x3 = x[2]
x3
x3[2] = 100
x
array([[ 1, 2, 3],
[ -3, 2, 4],
[ 5, -2, 100]])
import numpy as np
x = np.array([[1,2,3],[4,5,6]])
np.zeros_like(x)
array([[0, 0, 0],
[0, 0, 0]])