我试着跑python -m cProfile simple_test_script.py
。我在 Windows 7,Python 2.7.10 上。
simple_test_script.py:
import numpy as np
from numpy.linalg import eigvals
def run_experiment(niter=100):
K = 100
results = []
for _ in xrange(niter):
mat = np.random.randn(K, K)
max_eigenvalue = np.abs(eigvals(mat)).max()
results.append(max_eigenvalue)
return results
some_results = run_experiment()
print 'Largest one we saw: %s' % np.max(some_results)
我收到此错误:
File "<ipython-input-13-6634cb53f497>", line 1
python -m cProfile simple_test_script.py
^
SyntaxError: invalid syntax
我阅读了这份文档:https ://docs.python.org/2/library/profile.html
(如果 cProfile 在您的系统上不可用,请使用 profile 而不是 cProfile。)
我尝试了 profile 而不是 cProfile 但同样的错误。有什么线索可以调用 cProfile 吗?