0

I have list with different element size. Here is the attachment for the reference:

enter image description here

As can be seen in the image, first list element size is1095, second 16, third 66, and so on. This List should now be converted to a NumPy array. As far as I know, all of the List's elements should be the same size for conversion. However, I've seen some stack overflow posts stack overflow posts where individuals converted a list of different element sizes to a NumPy array with Null or 0 values to to the elements in order to do the size uniform.

However, I do not want to change my data via adding any 0 or Null values. Because I need to input it into the deep model as is. Is there a method to convert a list of elements (different component sizes) to a NumPy array without changing the data?

Ahmad
  • 645
  • 2
  • 6
  • 21

1 Answers1

-1

If you want to use the list as the input for your deep learning model, you can use the mask and padding. You can find it here https://www.tensorflow.org/guide/keras/masking_and_padding Check that it does not change your data to int. You need to use pad_sequences(x, dtype='float32') (or 'float64') or something like this.

  • Thanks. Somehow its working. But it converting data to `int`. Which ignore all the float information. How can you handle that? – Ahmad Mar 04 '22 at 05:46
  • 1
    You need to use pad_sequences(x, dtype='float32') (or 'float64', as you see fit) or something. –  Mar 04 '22 at 06:03
  • I went through your given link, there masking is done column wise. Here in my case it is in row wise. So the question is, would tensorflow keras also ignore these values? – Ahmad Mar 04 '22 at 06:45
  • Hi, my input layer is `input_layer = tf.keras.Input(shape=input_shape, name="time_series_activity") con_l1 = tf.keras.layers.Conv2D(64, (5, 1), activation="relu")(input_layer) `. How to add `mask_zero=True` here. As in the official documentation, its through `layers.Embedding`? – Ahmad Mar 04 '22 at 07:08
  • Does this concept is just for RNN models, not for others like CNN or hybrid model like CNN, LSTM, Attention etc? – Ahmad Mar 04 '22 at 07:18