import numpy as np
随机产生一个几行几列矩阵
a = np.random.randn(3, 10)
print a
[[1.16643954 1.61183689]]
numpy
x = np.array([[1,2,3,],[4,5,6]])
b = x.shape[1] 1代表几列
print b b=3
N = x.shape[0] 0代表行数
print N = 2
x_row = x.reshape(3, 2) # (N,D)
[[1 2]
[3 4]
[5 6]]
np.dot的用法
out = np.dot(x_row, 2) + 1 # (N,M) 2*x_row+1的结果
[[ 3 5]
[ 7 9]
[11 13]]
np.max函数的用法 axis=0参数表示按照列取最大值,等1表示按行取值
x = np.array([[1,2,3],[4,5,6]])
y = np.max(x, axis=0, keepdims=False)
print y
y2 = np.max(x, axis=1, keepdims=True)
print y2
y3 = np.max(x, axis=1, keepdims=False)
print y3
y = [4 5 6]
y2 = [[3] [6]]
y3= [3 6]
x = np.array([[-1,2,3],[-4,5,6]])
a_x = np.maximum(0, x)
print a_x
[[0 2 3]
[0 5 6]]
大于零的等于原来的值 小于零的等于0