In [ ]:
from IPython.display import display_pretty
import numpy as np
np.transpose
permute the dimensions of an arraynp.broadcast
np.expand_dims
expand shape of an arraynp.squeeze
np.asarray
np.asanyarray
np.asfarray
parse array to floatnp.asmatrix
np.asscalar
np.require
np.searchsorted
return the index where element should be inserted in maintain order
In [ ]:
a = [1, 2, 3]
b = [4, 5, 6]
np.column_stack((a, b))
In [ ]:
a = np.array([[1,2], [3,4]])
b = np.array([[5,6]])
x1 = np.concatenate((a, b), axis=0)
x2 = np.concatenate((a, b.T), axis=1)
display_pretty(x1, x2)
In [ ]:
a = np.array((1, 2, 3))
b = np.array((4, 5, 6))
np.dstack((a, b))
In [ ]:
a = np.array((0, 1, 2))
np.tile(a, 2)
In [ ]:
a = np.array([[1, 5, 3], [2, 3, 1]])
np.sort(a, axis=0)
In [ ]:
cond = [[True, False], [True, True]]
x = [[1, 2], [3, 4]]
y = [[9, 8], [7, 6]]
a = np.where(cond, x, y)
display_pretty(a)
# equal to blow
for c, xv, yv in zip(cond, x, y):
for c2, xv2, yv2 in zip(c, xv, yv):
print(xv2 if c2 else yv2, end=', ')
print()
x = np.arange(9).reshape((3, 3))
display_pretty(x > 5)
b = np.where(x > 5)
display_pretty(b)
# frequently use
c = np.where(x > 3, x, -1)
display_pretty(c)