from scipy.linalg import sqrtm
a1 = sqrtm(A)
'''
import math
math.sqrt( x )
'''
import numpy as np
a1 = np.finfo(np.float64).eps
a2 = np.max(A)
a3 = np.maximum(A,B)
a3 = np.diagonal(A)
1. np.multiply(A,B) 或者 A * B
2. np.dot(A,B)
C = A/B
C =np.dot(A,np.linalg.inv(B))
a=np.array([[1.,2.],[3.,4.]])
c=np.divide(a,a)
a = np.array([4,2,3])
b = np.array([2,5,7])
f = a/b
np.mat(A)
np.hstack()
np.vstack()
>>>import numpy as np
>>> c=[[1,2,3],[4,5,6],[7,8,9]]
>>> np.cumsum(c,axis=0)
array([[ 1, 2, 3],
[ 5, 7, 9],
[12, 15, 18]])
>>> np.cumsum(c,axis=1)
array([[ 1, 3, 6],
[ 4, 9, 15],
[ 7, 15, 24]])
a = np.sum(C,axis=1)
a = np.sum(C,axis=0)
b = np.ones(a.shape)
b = np.linalg.norm(a,ord = 2)
np.mean(now2,0)
np.mean(now2,1)
t11 = np.where(D < w , 0, 1)
t13 = (t11 == 1).all()
t13 = (t11 == 1).any()
azis, ranges = np.where(np.ones_like(a))
'''
a→
[[1 1 1 1]
[1 1 1 1]
[1 1 1 1]
[1 1 1 1]]
azis, ranges→
[0 0 0 0 1 1 1 1 2 2 2 2 3 3 3 3] [0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3]
'''
import numpy as np
a = np.arange(12).reshape(3,4)
print('a:', a)
print('np.where(a > 5):', np.where(a > 5))
print('a[np.where(a > 5)]:', a[np.where(a > 5)])
print('np.where(a > 5)[0]:', np.where(a > 5)[0])
print('np.where(a > 5)[1]:', np.where(a > 5)[1])
print(a[np.where(a > 5)[0], np.where(a > 5)[1]])
a: [[ 0 1 2 3]
[ 4 5 6 7]
[ 8 9 10 11]]
np.where(a > 5): (array([1, 1, 2, 2, 2, 2]), array([2, 3, 0, 1, 2, 3]))
a[np.where(a > 5)]: [ 6 7 8 9 10 11]
np.where(a > 5)[0]: [1 1 2 2 2 2]
np.where(a > 5)[1]: [2 3 0 1 2 3]
[ 6 7 8 9 10 11]
np.linspace(0,3,4)
B = np.tile(A, (M, N))
B = np.ones_like(A)
工作TIPS:
- 如果报错原因实在找不到,可以注释掉
- 调试时,关掉并行
- 先完成,再优化