简体   繁体   中英

How to insert in numpy array

There is Two matrices. The first one is data matrix with dimension of (85,7794,64) and the second one is flashing with dimension of (85,7794). I must extract some parts of data according to flashing matrix under a specific condition which is mentioned in below code. There is no doubt about condition performance, but when i try to insert the extracted data (with dimension of (20,64)) to predefined storage matrix with dimension of (85,3600,64)(3600 because 180 parts of data with dimension of (20,64) should be extracted from data, so 180*20 = 3600 ) it gives an error which is mentioned below. Thanks if anyone can helps to solve it.

ERROR:

ValueError: could not broadcast input array from shape (20,64) into shape (0,64)

storage_matrix = np.zeros((85,3600,64))


for i in range(0,84):    
    for j in range(0,7793):
        t = j + 1
        s = j + 20
        if Flashing[i,j] == 0 and Flashing[i,t] == 1:
            storage_matrix[i,j:s,:] = data[i,j:s,:]
            

Your range for the inner loop is too big. Consider what happens when j>3600 in the inner loop.

When you say storage_matrix[i, j:s, :] , and if j>3600 , the code breaks because the size of the middle dimension of storage_matrix is 3600. That returns an empty array. Hence you are seeing a zero dimension in your error message.

Not sure what you are trying to do here but maybe you meant 3600 in your inner loop.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM