Is there a pythonic way to convert a structured array to vector?
For example:
I'm trying to convert an array like:
[(9,), (1,), (1, 12), (9,), (8,)]
to a vector like:
[9,1,1,12,9,8]
                Use numpy .flatten() method
>>> a = np.array([[1,2], [3,4]])
>>> a.flatten()
array([1, 2, 3, 4])
>>> a.flatten('F')
array([1, 3, 2, 4])
Source: Scipy.org
You don't need to use any numpy, you can use sum:
myList = [(9,), (1,), (1, 12), (9,), (8,)]
list(sum(myList, ()))
result:
[9, 1, 1, 12, 9, 8]
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With