我是python3。
的新手我的代码正在遵循,我不知道如何解决此问题。
test = np.random.randn(10)
print (test)
TypeError: '>' not supported between instances of 'int' and 'str'
( (我已经导入numpy,并且详细的错误msg正在遵循。
TypeError Traceback (most recent call last)
<ipython-input-13-3e506a0fbc4a> in <module>()
1 test=np.random.randn(10)
----> 2 print(test)
/usr/local/lib/python3.6/site-packages/numpy/core/numeric.py in array_str(a, max_line_width, precision, suppress_small)
1937
1938 """
-> 1939 return array2string(a, max_line_width, precision, suppress_small, ' ', "", str)
1940
1941
/usr/local/lib/python3.6/site-packages/numpy/core/arrayprint.py in wrapper(self, *args, **kwargs)
386 repr_running.add(key)
387 try:
--> 388 return f(self, *args, **kwargs)
389 finally:
390 repr_running.discard(key)
/usr/local/lib/python3.6/site-packages/numpy/core/arrayprint.py in array2string(a, max_line_width, precision, suppress_small, separator, prefix, style, formatter)
521 else:
522 lst = _array2string(a, max_line_width, precision, suppress_small,
--> 523 separator, prefix, formatter=formatter)
524 return lst
525
/usr/local/lib/python3.6/site-packages/numpy/core/arrayprint.py in _array2string(a, max_line_width, precision, suppress_small, separator, prefix, formatter)
344 prefix="", formatter=None):
345
--> 346 if a.size > _summaryThreshold:
347 summary_insert = "..., "
348 data = _leading_trailing(a)
TypeError: '>' not supported between instances of 'int' and 'str'
在python3中,在比较元素时决定更严格。因此," int"one_answers" str"之间的比较会引起错误(此错误很难复制(。有很多方法可以解决此问题,我使用的一个选项是Numpy中的.tolist()
方法。
import numpy as np
test = np.random.randn(10)
print(test.tolist())
看起来您还没有包含import
函数。
尝试一下:
import numpy as np
test = np.random.randn(10)
print (test)
希望它有效:(
更改打印选项将使此数组走开。numpy中的默认阈值设置。
np.set_printoptions(threshold=5)