# -*- coding:utf-8 -*-
import numpy as np
def main():
lst = [[1, 3, 5], [2, 4, 6]]
print(type(lst)) # <type 'list'>
np_lst = np.array(lst)
print(type(np_lst)) # <type 'numpy.ndarray'>
# bool, int, int8, int16, int64 ..., uint8, float, float8
np_list = np.array(lst, dtype = np.float)
# 1 numpy property
print(np_list.shape) # pirnt: (2, 3)
print(np_list.ndim) # pirnt: 2
print(np_list.dtype) # pirnt: float64
print(np_list.itemsize) # pirnt: 8
print(np_list.size) # pirnt: 6
# 2 some arrays
print(np.zeros([2, 4])) #
print(np.ones([4, 3])) #
print("RandNum:")
print(np.random.rand(2, 4))
print("RandInt:")
print(np.random.randint(1, 10, 3))
print("Randn:")
print(np.random.randn(2, 4))
print("Distribute:")
print(np.random.beta(1, 10, 100))
# 3 Aarray Opers
lst = np.arange(1, 11).reshape([2, -1])
print("Exp")
print(np.exp(lst))
print(np.exp2(lst))
print(np.sqrt(lst))
print(np.sin(lst))
print("Log")
print(np.log(lst))
lst1 = np.array([10, 20, 30, 40])
lst2 = np.array([1, 2, 4, 5])
print("Add")
print(lst1 + lst2) # [11 22 34 45]
if __name__ == "__main__":
main()
#矩阵
import numpy as np# 4 linerfrom numpy.linalg import *
print(np.eye(3))
lst = np.array([[1, 2],
[3, 4]])
print("Inv: ")
print(inv(lst))
print("T: ")
print(lst.transpose())
print("Det:")
print(det(lst))
print(eig(lst))
y = np.array([[5.], [7.]])
print("Slove")
print(solve(list, y))