Home > Blockchain >  How to change the type of data from [[, , , ,]] to [[],[],[]]?
How to change the type of data from [[, , , ,]] to [[],[],[]]?

Time:09-04

is there any way to change the type of data?

In order to fit the model(or you can say function) that I'm using currently, I need to input a data type that is array of array, like this.

enter image description here

My current data looks like this.

enter image description here

Just some simple codes here.

#The code they provide(which is an arbitary one)
arr = 440.0 * np.ones([1, n_frames, 1], dtype=np.float32)

#My current one you can just go through a loop
arr_lst = []
for i in range(10):
    arr_lst.append(i)
arr_lst

CodePudding user response:

You can use list comprehension:

import numpy as np
arr = 440.0 * np.ones([1, 1, 1], dtype=np.float32)

#My current one you can just go through a loop
arr_lst = []
for i in range(10):
    arr_lst.append(i)

#Try list comprehension
[[x] for x in list(arr_lst)]

Ouput:

[[0], [1], [2], [3], [4], [5], [6], [7], [8], [9]]

CodePudding user response:

If I understood correctly you can reshape after changing arr_lst to numpy array

arr_lst = [i for i in range(10)]
arr = np.array(arr_lst).reshape(1, len(arr_lst), 1)
print(arr)

Output

[[[0]
  [1]
  [2]
  [3]
  [4]
  [5]
  [6]
  [7]
  [8]
  [9]]]
  • Related