我有一个numpy数组,当print
- ed看起来像这样:
print(a.shape)
(21,)
print(a)
[array([8.55570588e+03, 4.23078573e+05, 2.81254715e+07, 2.10356201e+09,
4.24558286e+05, 2.10032147e+07, 1.39638949e+09, 1.04453957e+11,
2.81593475e+07, 1.39354786e+09, 9.26480296e+10, 6.92992796e+12,
2.10047682e+09, 1.03982525e+11, 6.91296507e+12, 5.17021191e+14])
array([8.55404706e+03, 4.23328400e+05, 2.80891690e+07, 2.09651453e+09,
4.23874124e+05, 2.09628073e+07, 1.39044370e+09, 1.03745119e+11,
2.81060928e+07, 1.38935279e+09, 9.21288996e+10, 6.87207671e+12,
2.09626303e+09, 1.03584989e+11, 6.86712650e+12, 5.12107449e+14])
array([6.71569608e+03, 3.32364057e+05, 2.20526342e+07, 1.64564735e+09,
3.32826578e+05, 1.64539763e+07, 1.09116635e+09, 8.13888141e+10,
2.20612069e+07, 1.08976996e+09, 7.22409501e+10, 5.38629510e+12,
1.64474898e+09, 8.11907944e+10, 5.38026989e+12, 4.01021156e+14])
array([ 97, 120, 147, 106, 115, 151, 300, 268, 326, 454, 684,
1594, 2202, 2229, 1205, 2])
array([ 1, 0, 0, 0, 0, 1, 0, 1, 0, 2, 1,
11, 359, 1355, 3921, 4348])
array([ 1, 0, 0, 1, 0, 0, 6, 11, 31, 644, 2312,
3046, 3618, 321, 7, 2])
625.0 625.0 625.0 537178.875 1874648.75 1373895.875 1.275734191674592
2.066594119913508 1.6749058704798478 0.11276410212887233 2.55304393588347
1.1167704949278905 2.177796835501801 1.1323869527951895
1.3940068452456151]
理想情况下,我希望所有这些值都在一个大的长度数组中(3 * 16 + 3 * 16 + 15)
np.concatenate
无效,flatten
也确实带来了预期效果。
答案 0 :(得分:1)
一种简单的方法是使用np.hstack
来展平数组列表和浮点数。示例用法如下:
import numpy as np
a = [np.array([1, 2, 3]), np.array([4, 5, 6]), 7, 8, 9]
np.hstack(a)
>> array([1, 2, 3, 4, 5, 6, 7, 8, 9])