简体   繁体   中英

How do I easily convert a numpy.ndarray to a list of numpy.array?

I am currently struggling to parsing some data into a training framework.

The problem is that the framework is not able to handle ndarray. I need to convert into a list of array. The input and output data is currently stored as two seperate lists of numpy.ndarray.

  1. The input data has to be converted into a list of numpy array where each array contains a column of the ndarray.

  2. The output data has to be converted into a list of numpy arrays where each array contains the rows of the ndarray?..

Is it possible to convert it to this?

when i print train_output_data[0] i get this:

https://ufile.io/fa816

Assuming ip and op are the input list and output lists respectively,

newInput = [ip[:,i] for i in range(ip.shape[0])]
newOutput = [x for x in op]

If the train_output_data and train_input_data are lists of 2D numpy.ndarray 's, then the alternative can be

newInput = []
for ip in train_input_data:
    newInput.append([ip[:,i] for i in range(ip.shape[0])])

newOutput = []
for op in train_output_data:
    newOutput.append([x for x in op])

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