np.zeros
用法:zeros(shape, dtype=float, order=‘C’)
返回:返回来一个给定形状和类型的用0填充的数组;
参数:shape:形状
dtype:数据类型,可选参数,默认numpy.float64
dtype类型:t ,位域,如t4代表4位
b,布尔值,true or false
i,整数,如i8(64位)
u,无符号整数,u8(64位)
f,浮点数,f8(64位)
c,浮点负数,
o,对象,
s,a,字符串,s24
u,unicode,u24
order:可选参数,c代表与c语言类似,行优先;F代表列优先
例子:
np.zeros(5)
array([ 0., 0., 0., 0., 0.])
np.zeros((5,), dtype=np.int)
array([0, 0, 0, 0, 0])
np.zeros((2, 1))
array([[ 0.],
[ 0.]])
s = (2,2)
np.zeros(s)
array([[ 0., 0.],
[ 0., 0.]])
np.reshape
reshpae,是数组对象中的方法,用于改变数组的形状。
二维数组
import numpy as np
a=np.array([1, 2, 3, 4, 5, 6, 7, 8])
print a
d=a.reshape((2,4))
print d
三维数组
import numpy as np
a=np.array([1, 2, 3, 4, 5, 6, 7, 8])
print a
f=a.reshape((2, 2, 2))
print f
变换与卷绕
线性变换:
1.直线还是直线
2.比例保持不变
3.原点不变
仿射变换:
1.直线还是直线
2.比例保持不变
旋转矩阵T[cos -sin
sin cos]
numpy.eye
numpy.eye(N, M=None, k=0, dtype=<class ‘float’>, order=‘C’)[source]
Return a 2-D array with ones on the diagonal and zeros elsewhere.
Parameters:
N : int
Number of rows in the output.
M : int, optional
Number of columns in the output. If None, defaults to N.
k : int, optional
Index of the diagonal: 0 (the default) refers to the main diagonal, a positive value refers to an upper diagonal, and a negative value to a lower diagonal.
dtype : data-type, optional
Data-type of the returned array.
order : {‘C’, ‘F’}, optional
Whether the output should be stored in row-major (C-style) or column-major (Fortran-style) order in memory.
New in version 1.14.0.
Returns:
I : ndarray of shape (N,M)
An array where all elements are equal to zero, except for the k-th diagonal, whose values are equal to
numpy中的切片操作小结
https://blog.csdn.net/ccwlisha/article/details/88866429