Reputation: 649
I am trying to transpose this array into single one. My input:
a = [[ array([ 3.00514850e+05, 3.32400000e+01, 2.71669002e-01,
6.50974961e+05, 3.00515112e+05, 3.32248995e+01])
array([ 15.])]
[ array([ 3.00915200e+05, 2.90600000e+01, 2.91730634e-01,
6.50763121e+05, 3.00915412e+05, 2.91246275e+01])
array([ 17.])]
What i am trying to achieve:
b = [[ 3.00514850e+05, 3.32400000e+01, 2.71669002e-01,
6.50974961e+05, 3.00515112e+05, 3.32248995e+01, 15.]
[ 3.00915200e+05, 2.90600000e+01, 2.91730634e-01,
6.50763121e+05, 3.00915412e+05, 2.91246275e+01, 17.]]
So my plan is to first transpose my array into single one, split two arrays into individual and then append it together. I really feel like I over-complicating something.
I used b = a.transpose() to put all the values from small array to the end. After that i am trying to use c, d = ([i] for i in b) to split this to arrays and then my plan is to use output = np.append(c, d).
But my function c, d trowing error "too many values to unpack (expected 2)".
Is there any better way to do it? What am I doing wrong? Can you help me?
Upvotes: 1
Views: 544
Reputation: 3483
So you are trying to concatenate the arrays in all the sublist of your list a
. You can do that using the built-in function map
:
a = [[np.array([3.00514850e+05, 3.32400000e+01, 2.71669002e-01,
6.50974961e+05, 3.00515112e+05, 3.32248995e+01]), np.array([15.])],
[np.array([3.00915200e+05, 2.90600000e+01, 2.91730634e-01,
6.50763121e+05, 3.00915412e+05, 2.91246275e+01]), np.array([17.])]]
a = np.array(a)
result = np.array(list(map(np.concatenate,a)))
Upvotes: 3