开发者

Splitting arrays python

开发者 https://www.devze.com 2023-04-05 04:33 出处:网络
I have a 2D array in Python either a normal one or a numpy array with dimensions (150, 5), I wish to split it into two开发者_如何学运维 arrays of dimensions (150, 3) and (150, 2) respectively. Somehow

I have a 2D array in Python either a normal one or a numpy array with dimensions (150, 5), I wish to split it into two开发者_如何学运维 arrays of dimensions (150, 3) and (150, 2) respectively. Somehow I haven't been able to do it.

Any suggestions?


for numpy arrays you can slice them like this:

a, b = the_array[...,:3], the_array[...,3:]

and with lists of lists (that's what I understand for "normal arrays")

a, b = [i[:3] for i in the_array], [i[3:] for i in the_array]
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号