import numpy as np
np.random.seed(0)
x1 = np.random.randint(10,size=6)
x2 = np.random.randint(10,size=(3,4))
x3 = np.random.randint(10,size=(3,4,5))
print('x3 ndim: ',x3.ndim)
print('x3 shape:',x3.shape)
print('x3 size: ',x3.size)
print(x1)
print('dtype:',x3.dtype)
print('itemsize:',x3.itemsize,'bytes')
print('nbytes:',x3.nbytes,'bytes')
x1
x1[0]
x1[4]
x1[-1]
x1[-2]
x2
x2[0,0]
x2[2,0]
x2[2,-1]
x2[0,0] = 12
x2
x1[0] =3.14159
x1
x = np.arange(10)
x
x[:5]
x[5:]
x[4:7]
x[::2]
x[1::2]
x[::-1]
x[5::-2]
x2
x2[:2,:3]
x2[:3,::2]
x2[::-1,::-1]
x2[:,0]
x2[0,:]
x2[0]
x2
x2_sub = x2[:2,:2]
x2_sub
x2_sub[0,0] = 99
x2
x2_sub_copy = x2[:2,:2].copy()
x2_sub_copy
x2_sub_copy[0,0] = 42
x2_sub_copy
x2
grid = np.arange(1,10).reshape((3,3))
grid
x = np.array([1,2,3])
x.shape
x.reshape((1,3))
a = x[np.newaxis,:]
a = a[np.newaxis,:]
a.shape
x.reshape((3,1))
x[:,np.newaxis].shape
x = np.array([1,2,3])
y= np.array([3,2,1])
np.concatenate([x,y])
z = [99,99,99]
np.concatenate([z,x,y])
grid = np.array([[1,2,3],
[4,5,6]])
np.concatenate([grid,grid])
np.concatenate([grid,grid],axis=1)
x = np.array([1,2,3])
grid = np.array([[9,8,7],[6,5,4]])
np.vstack([x,grid])
y = np.array([[99],[99]])
np.hstack([grid,y])
x = [1,2,3,99,99,3,2,1]
x1,x2,x3 = np.split(x,[3,5])
print(x1,x2,x3)
grid = np.arange(16).reshape((4,4))
grid
upper,lower = np.vsplit(grid,[2])
print(upper)
print(lower)
left,right = np.hsplit(grid,[2])
print(left)
print(right)