我使用numpy.loadtxt
加载了一个包含以下scructure的文件:
99 0 1 2 3 ... n
46 0.137673 0.147241 0.130374 0.155461 ... 0.192291
32 0.242157 0.186015 0.153261 0.152680 ... 0.154239
77 0.163889 0.176748 0.184754 0.126667 ... 0.191237
12 0.139989 0.417530 0.148208 0.188872 ... 0.141071
64 0.172326 0.172623 0.196263 0.152864 ... 0.168985
50 0.145201 0.156627 0.214384 0.123387 ... 0.187624
92 0.127143 0.133587 0.133994 0.198704 ... 0.161480
现在,我需要第一列(除了第一行)存储该行中较高值的索引。你知道吗
最后,将此数组保存在与原始数组相同的数字格式的文件中。你知道吗
谢谢
你能用这样的
numpy.argmax
吗:注意,
np.savetxt
允许格式化。你知道吗此示例代码没有说明您希望跳过第一行的事实,您可能希望从
np.argmax
的结果中减去1,这取决于剩余列中的索引是否包含索引列(0)。你知道吗您的数据看起来像一个带有列和索引的数据帧:数据类型是非同构的。使用
pandas
更方便,它本机管理此布局:那么
out.txt
就是相关问题 更多 >
编程相关推荐