Numpy
这是一个三方的库,是很多科学与工程库的基础。在机器学习中应用广泛。
import numpy as np。
数组运算
import numpy as npax = np.array([1, 2, 3, 4])
ay = np.array([5, 6, 7, 8])type(ax)
print(f'{ax} * 2 = {ax * 2}') #[2 4 6 8]
print(f'{ax} + 10 = {ax + 10}') #[11 12 13 14]
矩阵运算
import numpy as np
"""
[[ 1 -2 3][ 0 4 5][ 7 8 -9]]
"""
m = np.matrix([[1,-2,3],[0,4,5],[7,8,-9]])
print(f'm is:\n{m}')"""
[[ 1 0 7][-2 4 8][ 3 5 -9]]
"""
print(f'm.T is:\n{m.T}')
"""
[[ 0.33043478 -0.02608696 0.09565217][-0.15217391 0.13043478 0.02173913][ 0.12173913 0.09565217 -0.0173913 ]]
"""
print(f'm.I is:\n{m.I}')v = np.matrix([[2],[3],[4]])
print(f'v is:\n{v}')
"""
[[ 8][32][ 2]]
"""
print(f'm * v is:\n{m * v}')