I have a data set like this,
data = np.array([[ 5, 31, 61],
[ 10, 31, 67],
[ 15, 31, 69],
[ 4, 31, 72],
[ 14, 31, 73],
[ 21, 31, 77],
[ 19, 31, 78]])
I want to convert it into arrays in list for every single row. I tried,
np.split(data,len(data))
#[array([[ 5, 31, 61]]),
# array([[10, 31, 67]]),
# array([[15, 31, 69]]),
# array([[ 4, 31, 72]]),
# array([[14, 31, 73]]),
# array([[21, 31, 77]]),
# array([[19, 31, 78]])]
But as you can see it gives double [
to me. What I simply want is;
[np.array([5, 31, 61]),
np.array([10, 31, 67]),
np.array([15, 31, 69]),
np.array([4, 31, 72]),
np.array([14, 31, 73]),
np.array([21, 31, 77]),
np.array([19, 31, 78])]
CodePudding user response:
What about taking advantage of unpacking?
lst = [*data]
or:
lst = list(data)
output:
[array([ 5, 31, 61]),
array([10, 31, 67]),
array([15, 31, 69]),
array([ 4, 31, 72]),
array([14, 31, 73]),
array([21, 31, 77]),
array([19, 31, 78])]