a = np.arange(16).reshape(4,4)
# transpose
a.T
a.transpose()
#inverse
np.linalg.inv(a)
# 矩阵乘法
np.dot(a,a)
# trace
np.trace(a)
# eigen values and vectors
np.linalg.eig(a)
# 解线性方程组ax=b
a = np.array([[3,1], [1,2]])
b = np.array([9,8])
x = np.linalg.solve(a, b)
>>> c = a.view() # c is a view of the data >>> c is a
False>>> c.shape = 2,6# a's shape doesn't change>>> a.shape
(3, 4)
>>> c[0,4] = 1234# a's data changes>>> a
array([[ 0, 1, 2, 3],
[1234, 5, 6, 7],
[ 8, 9, 10, 11]])
# Slicing an array returns a view of it:>>> s = a[ : , 1:3]
>>> s[:] = 10# s[:] is a view of s. Note the difference between s=10 and s[:]=10>>> a # a changed
array([[ 0, 10, 10, 3],
[1234, 10, 10, 7],
[ 8, 10, 10, 11]])
Deep Copy
>>> d = a.copy() # a new array object with new data is created>>> d is a
False>>> d.base is a # d doesn't share anything with aFalse>>> d[0,0] = 9999>>> a
array([[ 0, 10, 10, 3],
[1234, 10, 10, 7],
[ 8, 10, 10, 11]])