I am learning python and I am having a little bit of trouble while handling an object. I have tried to look for a solution but it led nowhere, so I am asking you guys.
I want to get the first X columns of an object, but I can't as it doesn't have the same size in every row.
I have this object:
array([[45, 45, 45, 50, 51, 50, 50, 50, 51, 50, 52],
[45, 45, 45, 50, 51, 50, 50, 50, 51, 50, 51, 52, 55],
[45, 45, 45, 50, 51, 50, 52, 50, 50, 50, 51],
[50, 51, 52, 55, 50, 52, 50, 50, 50, 51, 50, 51]], dtype=object)
And I would like to get something like this:
array([[45, 45, 45, 50],
[45, 45, 45, 50],
[45, 45, 45, 50],
[50, 51, 52, 55]])
What could I do to solve this? Thanks for your help
Alvaro
What about
import numpy as np
data = np.array([[45, 45, 45, 50, 51, 50, 50, 50, 51, 50, 52],
[45, 45, 45, 50, 51, 50, 50, 50, 51, 50, 51, 52, 55],
[45, 45, 45, 50, 51, 50, 52, 50, 50, 50, 51],
[50, 51, 52, 55, 50, 52, 50, 50, 50, 51, 50, 51]], dtype=object)
newData = np.array([d[:4] for d in data])
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