Marco
Marco

Reputation: 25

Splitting array into multiple ones

I'd like to split my array into multiple ones: The original array looks as follows:

array([[228.6311346 , 228.6311346 , 228.6311346 ],
       [418.57914851,   0.        , 228.321311  ],
       [416.83133465,   0.        , 723.25171282]])

The resulting arrays should look like this:

array1([228.6311346, 418.57914851, 416.83133465])
array2([228.6311346, 0., 0.])
array3([228.6311346, 228.321311, 723.25171282])

Upvotes: 0

Views: 78

Answers (1)

Saket Anand
Saket Anand

Reputation: 35

for i in range(len(array)):
    exec("array"+str(i+1)+"=array["+str(i)+"]")

It will create your variable dynamically and assign the corresponding value to it.

array = [[1],[2],[3]]
print(array0) // outputs [1] after running above code

You can also use numpy.hsplit Doc Here

numpy.hsplit(ary, indices_or_sections)
# Split an array into multiple sub-arrays of equal size.

Upvotes: 1

Related Questions