[英]What is the process of this program written in Python?
I have to understand the process of a program which looks like measuring the performance of multiplication for several repeat sizes.我必须了解一个程序的过程,该程序看起来像是测量多个重复大小的乘法性能。
I tried to execute the program, but there was no clue to understand it from the output.我试图执行该程序,但没有从输出中理解它的线索。 I need a help how to use this program and please let me know what are input and output of it.我需要如何使用这个程序的帮助,请让我知道它的输入和输出是什么。
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()
When I executed the above code, its output was below.当我执行上面的代码时,它的输出如下。
$ python sample.py
usage: sample.py <filename>
I have executed the program like below.我已经执行了如下所示的程序。 There was no change on the code of "sample.py". “sample.py”的代码没有变化。 How can I fix the error and what is the appropriate content in fileToRead.txt?如何修复错误以及 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文件读取.txt
3.1415926535
It seems you are new to the world of programming.看来您是编程世界的新手。 "sys.argv" is used to take Command Line Arguments . “sys.argv”用于获取命令行参数。
The Expected Working of the program is:该计划的预期工作是:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.