【发布时间】:2026-01-03 07:00:02
【问题描述】:
我必须了解一个程序的过程,该程序看起来像是测量多个重复大小的乘法性能。
我试图执行该程序,但从输出中没有任何线索可以理解它。我需要帮助如何使用这个程序,请告诉我它的输入和输出。
import sys
import numpy as np
import matplotlib.pyplot as plt
if len(sys.argv) != 2:
print ("usage:", sys.argv[0], "<filename>")
exit()
a = np.loadtxt(sys.argv[1])
print(a)
list1, list2 = zip(*a)
plt.plot(list1, list2)
plt.show()
当我执行上面的代码时,它的输出如下。
$ python sample.py
usage: sample.py <filename>
按照答案试用
我已经执行了如下程序。 “sample.py”的代码没有变化。 如何修复错误以及 fileToRead.txt 中的相应内容是什么?
$ python sample.py fileToRead.txt
3.1415926535
Traceback (most recent call last):
File "arrmultbysize.py", line 24, in <module>
list1, list2 = zip(*a)
TypeError: iteration over a 0-d array
fileToRead.txt
3.1415926535
【问题讨论】:
-
不是代码错误...请做一些基础研究
标签: python python-3.x input output