简体   繁体   中英

How to split a multidimensional array of arrays into multiple single arrays in python?

Consider that I have a large data set that is a multidimensional array m_array .

m_array[['x', 'y', x],['a', 'b', c] ['1', '2', 3]] <--- x number arrays. Don't know how many.

Inside this multi-array I have x number of arrays (smaller data sets) and I don't know how many arrays are in the m_array

What is the best way to break down m_array and extract each array inside it into separate lists.

So have the following:

a_1['x', 'y', x]

a_2['a', 'b', c]

a_3['1', '2', 3]

You can use:

for i in range(len(m_array)):
    exec("a_%d = %s" % (i + 1, repr(m_array[i])))

How are you going to use variables with dynamic names? Don't do this. Chances are there are better ways to solve the problem. If you create dynamically named variables, you don't quite have a good handle to them.

You should use m_array directly.

In [17]: [print(i) for i in m_array]
['x', 'y', 'x']
['a', 'b', 'c']
['1', '2', 3]

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