I need to select the area of ​​a four-dimensional array in order to continue working with this area.

prepare_weights_inp2(model): weights=model.get_weights() _weights_=[] shape=[0,0,0,0] for weight in weights: ui=list(copy.copy(weight.shape)) while len(ui) < 4: ui.append(0) _weights_.append(ui) for ind , dim in enumerate(ui): if shape[ind] < dim: shape[ind]=dim mask=np.zeros(shape) ls=[0,0,0,0] q1=lambda sc : np.indices(range(ls[sc],_shape_[sc])) dynamic_x=_weights_[0][0] for _shape_ in _weights_: _shape_[0]=dynamic_x q,w,e,r=q1(0),q1(1),q1(2),q1(3) mask[q,w,e,r]=weights dynamic_x+=weight.shape[0] ls=[o+1 for o in copy.copy(_shape_)] return mask 

weights = model.get_weights () returns a list () object filled with n-dimensional (up to 4) np.array errors:

 mask[q,w,e,r]=weights ValueError: setting an array element with a sequence. 

Layout task on 2D array

  arr=np.zeros([10,20]) arr[:3][:2]=np.ones([2,1]) 

A mask is just a blank canvas.

example of melon

 from keras.layers import Input , Dense , Conv2D , MaxPooling2D , Flatten from keras.models import Sequential from keras.models import Model import numpy as np import cv2 x=np.zeros([1,1000,580,1]) input_image = Input(shape=(1000,580,1),name='input_image') conv_1 = Conv2D(2,kernel_size=(4,4),padding='valid',activation='relu',name='conv_1')(input_image) max_pooling_1=MaxPooling2D(4,(4,4),padding='valid',name='max_pooling_1')(conv_1) dense_1 = Dense(24, activation='relu',name='dense_1')(max_pooling_1) dense_2 = Dense(24, activation='relu',name='dense_1_2')(dense_1) output= Dense(1, activation='sigmoid',name='out')(dense_2) model = Model(inputs=input_image, outputs=output) model.compile(optimizer='rmsprop', loss='categorical_crossentropy', metrics=['accuracy']) 
  • You are trying to put an array in a cell with a number, are you sure that you want exactly this? - Komdosh
  • I am redirecting the list of cells q, w, e, r = q1 (0), q1 (1), q1 (2), q1 (3) in mask - Sahar Vkusni
  • Well, I mean, here here is mask = np.zeros (shape), you hammer in a 4-dimensional array, but then it turns out you should have a five-dimensional one, since 4 indices point to the next array, and not to the final element - Komdosh
  • it is not clear what and how you want to select in 4D arrays. Give a small example of the input data and what you want to get at the output ... - MaxU
  • one

0