import numpy as np
vector = np.array([5,10,15])
matrix = np.array([[2,3,4],[3,4,5]])
print(vector)
print(matrix)
print(vector.shape)
print(matrix.dtype)
world_alcohol = numpy.genfromtxt("C:/Users/TianYi ZHENG/Desktop/world_alcohol.txt",delimiter=",",dtype=str,skip_header=1)
print(world_alcohol)
'''
[['1986' 'Western Pacific' 'Viet Nam' 'Wine' '0']
['1986' 'Americas' 'Uruguay' 'Other' '0.5']
['1985' 'Africa' "Cte d'Ivoire" 'Wine' '1.62']
...
['1987' 'Africa' 'Malawi' 'Other' '0.75']
['1989' 'Americas' 'Bahamas' 'Wine' '1.5']
['1985' 'Africa' 'Malawi' 'Spirits' '0.31']]
'''
uruguay_other_1986 = world_alcohol[1:4]
matrix = np.array([[5,10,15], [20,25,30],[35,40,45]])
print(matrix[:,0:2])
'''
[[ 5 10]
[20 25]
[35 40]]
'''
a = np.arange(15).reshape(3,5)
print(a)
'''
[[ 0 1 2 3 4]
[ 5 6 7 8 9]
[10 11 12 13 14]]
'''
print(a.shape)
c = np.zeros((3,4) )
d = np.ones((2,3,4),dtype=np.int32)
print(d)
'''
[[[1 1 1 1]
[1 1 1 1]
[1 1 1 1]]
[[1 1 1 1]
[1 1 1 1]
[1 1 1 1]]]
'''
e = np.arange(0,20,5)
print(e)
f = np.random.random((2,3))
print(f)
g = np.linspace(0,5,100)
print(g)
a = np.array([10,20,30,40])
b = np.arange(4)
print(a)
print(b)
c = a-b
print(c)
print(c-1)
A = np.array([[1,1],[0,1]])
B = np.array([[2,0],[3,4]])
print(A)
print("*"*100)
print(B)
print(A*B)
print("*"*100)
print(A.dot(B))
print("*"*100)
print(np.dot(A,B))
import numpy as np
A = np.array([[1,2],[3,4]])
B = np.array([[5,6],[7,8]])
print(np.vstack((A,B)))
print(np.hstack((A,B)))
a = np.floor(10*np.random.random((2,12)))
print(a)
'''
[[5. 9. 0. 6. 2. 6. 4. 2. 4. 0. 5. 3.]
[7. 9. 6. 3. 1. 6. 5. 2. 8. 2. 6. 7.]]
'''
print("*"*100)
print(np.hsplit(a,3))
'''
[array([[5., 9., 0., 6.],
[7., 9., 6., 3.]]), array([[2., 6., 4., 2.],
[1., 6., 5., 2.]]), array([[4., 0., 5., 3.],
[8., 2., 6., 7.]])]
'''
print("*"*100)
print(np.hsplit(a,(3,4)))
'''
[array([[9., 0., 9.],
[3., 3., 5.]]), array([[4.],
[4.]]), array([[9., 3., 1., 1., 2., 9., 2., 3.],
[1., 9., 7., 9., 9., 6., 1., 6.]])]'''
print("*"*100)
a = np.array([[4,3,5],[1,2,1]])
print(a)
b = np.sort(a,axis=1)
print(b)
b = np.sort(a,axis=0)
print(b)