numpy.arange(start,end,step)
創建一個numpy 對象
如
numpy.arange(1,7) #[1 2 3 4 5 6]
跟序列的有點相似,range方法吧
numpy對象的dtype 屬性是一個描述對象本身的一個類型
a =- numpy.arange(1,7)
b = a.astype(numpy.str_)
print(a,b,sep="\n")
#[1 2 3 4 5 6]
#['1' '2' '3' '4' '5' '6']
a.astype 並不會改變a對這個地址的描述,改變的只是b對這個地址的描述
numpy.dtype 打印出元素類型
print(a.dtype) #int32
a.shape #(6,) shape 表示數組的維度
a.reshape((2,3)) #改變數組的維度 二行三列 [[1 2 3]
[4 5 6]]
ravel 將numpy對象變成一維
a = np.arange(1,7)
a.reshape(2,3)
print(a)
print(a.ravel())
[[1 2 3]
[4 5 6]]
[1 2 3 4 5 6]
[1 2 3 4 5 6]
複製變維 flatten
複製,類似於 深拷貝
就地變維
nmpy.shape = ()
組合
垂直組合
v = numpy.vstack((u,d))
# b [0 2 3 4 5 6]
# c [1 2 3 4 5 6]
c = np.vstack((b,c))
print(c)
[[0 2 3 4 5 6]
[1 2 3 4 5 6]]
水平組合
h = numpy.hstack((l,r))
# b [0 2 3 4 5 6]
# c [1 2 3 4 5 6]
c = numpy.hstack((b,c))
[0 2 3 4 5 6 1 2 3 4 5 6]
行組合
r = numpy.row_stack((u,d))
u: [1 2 3]
d: [4 5 6]
r :[[1 2 3]
[4 5 6]]
類組合
c = numpy.column_stack ((l, r))
l: [1 2 3]
r: [4 5 6]
c: [[1 4]
[2 5]
[3 6]]
分割
1)垂直分割
u,m,d = numpy.vsplit(v,3)
# b [[1 2 3] [ 3 4 5 ]]
a,v = np.vsplit(b,2)
print(a,v)
#[[1 2 3]] [[4 5 6]]
2)水平分割
a,b,c = numpy.hsplit(v,3)
[[1 2 3]
[4 5 6]
[7 8 9]]
[[1]
[4]
[7]]
[[2]
[5]
[8]]
3)深度分割
x, y = numpy.dsplit (d, 2)