Numpy 数组 - 当索引等于指定值时重新组合值
我对 numpy 数组很陌生,无法为我的问题找到一个很好的解释/示例。我看到了诸如 take() 或 take_along_axis() 之类的东西,但我不明白发生了什么...
我有这个 2D numpy,它可能包含 N 个子数组,每个子数组有 5 个值 (h, s, i, x , y):
values = np.array([
[1,2,3,4,5],
[1,22,33,44,55],
[1,22,333,444,555],
[1,22,333,4444,5555],
[1,222,33,44,55],
[1,222,330,440,550],
[10,20,30,40,50],
[100,200,300,400,500],
])
如您所见,同一索引的值可以重复。 我想通过索引值重新组合子数组,例如:
1
2
3
4
5
22
33
44
55
333
444
555
4444
5555
222
33
44
55
330
440
550
10
20
30
40
50
100
200
300
400
500
目标是获得常规数组,例如:
array = [1, 2, 3, 4 , 5, 22, 33, 44, 55, 333, 444, 555, 4444, 5555, 222, 33, 44, 55, 330, 440, 550, 10, 20, 30, 40, 50, 100, 200, 300, 400, 500]
非常感谢您的支持。
I'm pretty new to numpy arrays, and was not able to find a good explanation / example for my issue. I saw things like take() or take_along_axis() but I didn't understood what was going on...
I have this 2D numpy, which may contain N sub-arrays, of each 5 values (h, s, i, x, y):
values = np.array([
[1,2,3,4,5],
[1,22,33,44,55],
[1,22,333,444,555],
[1,22,333,4444,5555],
[1,222,33,44,55],
[1,222,330,440,550],
[10,20,30,40,50],
[100,200,300,400,500],
])
As you can see, values can be repeated for a same index.
I want to regroup sub-arrays, by indexes values, such as:
1
2
3
4
5
22
33
44
55
333
444
555
4444
5555
222
33
44
55
330
440
550
10
20
30
40
50
100
200
300
400
500
The goal is to obtain a regular array like:
array = [1, 2, 3, 4 , 5, 22, 33, 44, 55, 333, 444, 555, 4444, 5555, 222, 33, 44, 55, 330, 440, 550, 10, 20, 30, 40, 50, 100, 200, 300, 400, 500]
Thank you very much for your support.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
展平
方法列表(values.flatten())
you can use
flatten
methodlist(values.flatten())