技巧
Numpy
import numpy as np
A = np.random.randn(3,3)
B = np.random.randn(3,3)
print('A:\n{0}\n B:\n{1}'.format(A,B))
A:
[[-0.16819223 -0.65005007 -1.45306835]
[ 0.14667478 -1.40195255 -0.12871305]
[-0.86260073 0.25187163 -2.58701945]]
B:
[[-0.36228023 -1.5495955 -0.43543578]
[-0.44032362 0.68811886 -0.40343672]
[ 0.07358677 -0.64011174 -1.66832965]]
C = np.maximum(A,B)
D = np.minimum(A,B)
print('取A/B对应位置最大值:',C,sep='\n')
print('取A/B组对应位置最小值:',D,sep='\n')
取A/B对应位置最大值:
[[-0.16819223 -0.65005007 -0.43543578]
[ 0.14667478 0.68811886 -0.12871305]
[ 0.07358677 0.25187163 -1.66832965]]
取A/B组对应位置最小值:
[[-0.36228023 -1.5495955 -1.45306835]
[-0.44032362 -1.40195255 -0.40343672]
[-0.86260073 -0.64011174 -2.58701945]]
C = np.maximum(A,0)
print('relu(A):\n{}'.format(C))
relu(A):
[[0. 0. 0. ]
[0.14667478 0. 0. ]
[0. 0.25187163 0. ]]
C = np.random.normal(0,1,(3,3))
print('高斯分布:\n{}'.format(C))
高斯分布:
[[ 2.38548299 -0.66467181 -0.23646556]
[-0.13876203 -0.35762595 -0.44623119]
[-0.78050996 0.01327971 0.20492358]]
d={'a':1,'c':3,'b':2}
d_order=sorted(d.items(),key=lambda x:x[1],reverse=False)
print(d_order)
[('a', 1), ('b', 2), ('c', 3)]
d=[{'a':1},{'a':3},{'a':2}]
d_order = sorted(d,key=lambda x:x['a'],reverse=True)
print(d_order)
[{'a': 3}, {'a': 2}, {'a': 1}]
BUG
a = A
b = A,
print('type of (A):{}\ntype of (A,):{}'.format(type(a),type(b)))
type of (A):<class 'numpy.ndarray'>
type of (A,):<class 'tuple'>
## 默认并不是间隔为1进行划分,而是点数为50进行划分
len_lin = len(np.linspace(-6,-1))
len_log = len(np.logspace(-6,-1))
print('len(np.linspace(-6,-1)):',len_lin,'\nlen(np.logspace(-6,-1)):',len_log)
len(np.linspace(-6,-1)): 50
len(np.logspace(-6,-1)): 50