from numpy import newaxis
import numpy as np
a = np.floor(10*np.random.random((2,2)))
b = np.floor(10*np.random.random((2,2)))
print(a ,'\n\n', b, '\n\n')
print (np.column_stack((a,b)))
#[[ 0. 8.]#[ 2. 4.]] #[[ 8. 1.]#[ 7. 5.]] #[[ 0. 8. 8. 1.]# [ 2. 4. 7. 5.]]# 将原来的数组进行更高维度的装换,之后拼接
c = np.column_stack((a[:,newaxis],b[:,newaxis]))
print (c)
c.shape # (2, 2, 2)#[[ 3. 1.]# [ 8. 5.]] # [[ 6. 3.]# [ 0. 7.]] #[[[ 3. 1.]# [ 6. 3.]]# [[ 8. 5.]# [ 0. 7.]]]# For arrays of with more than two dimensions, hstack stacks along their second axes, vstack stacks along their first axes, and concatenate allows for an optional arguments giving the number of the axis along which the concatenation should happen.
数组拆分
from numpy import newaxis
import numpy as np
a = np.floor(10*np.random.random((2,12)))
print(a)
a.shape
print(100* '*')
# 原始的数组竖直切断,分成原始数组的3份的数组
c = np.hsplit(a,3) # Split a into 3
print(c)
print(len(c))
print(c[0].shape)
print(100* '*')
new = np.floor(10*np.random.random((2,12)))
print(new)
print(100* '*')
d = np.hsplit(new,(3,4)) # Split a after the third and the fourth column
print(d)
print(len(d))
i = 0while i < len(d):
print(d[i].shape)
i = i + 1
print(100* '*')
from numpy import newaxis
import numpy as np
a = np.arange(12).reshape(2,6)
c = a.view()
print(a, type(a))
print(c is a)
print(c.base is a) # c is a view of the data owned by a
print(c.flags.owndata)
c.resize(3, 4) # a's shape doesn't change
print(a.shape)
c[0,2] = 1234# a's data changes
print(a)
print(100 * '-')
print(c)