我在MATLAB中有這個功能功能numpy.reshape
cn = reshape (repmat (sn, n_rep, 1), 1, []);
與鍵碼號蟒蛇:
import numpy like np
from numpy.random import randint
M = 2
N = 2 * 10 ** 8 ### data value
n_rep = 3 ## number of repetitions
sn = randint (0, M, size = N) ### integers 0 and 1
print ("sn =", sn)
cn_repmat = np.tile (sn, n_rep)
print ("cn_repmat =", cn_repmat)
cn = np.reshape (cn_repmat, 1, [])
print (cn)
我不知道,如果復古親屬不知道
File "C:/Users/Sergio Malhao/.spyder-py3/Desktop/untitled6.py", line 17, under <module>
cn = np.reshape (cn_repmat, 1, [])
File "E: \ Anaconda3 \ lib \ site-packages \ numpy \ core \ fromnumeric.py", line 232, in reshape
return _wrapfunc (a, 'reshape', newshape, order = order)
File "E: \ Anaconda3 \ lib \ site-packages \ numpy \ core \ fromnumeric.py", line 57, in _wrapfunc
return getattr (obj, method) (* args, ** kwds)
ValueError: Can not reshape the array of size 600000000 in shape (1,)
我得到這個:sn [0 1 0 ...,111], cn_repmat [[0 1 0 ...,111]], cn = [[0 1 0 ..., 1 1 1]] Mikaelblomkvistsson –
恭喜。這是正確的還是什麼?如果你想精確到一維,寫:cn = np.squeeze(np.reshape(cn_repmat,(1,-1))) – Mikaelblomkvistsson