从矩阵到numpy数组

时间:2017-08-08 11:11:13

标签: python arrays numpy

当我尝试创建2D数组时, 我按照接下来的步骤, 但我无法创建一个numpy数组

import numpy as np
b = np.array([(1,0), (0.33,0.67)])

但是我收到以下错误

 ---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-54-4851c8fca996> in <module>()
----> 1 print(b)

C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\numeric.py in array_str(a, max_line_width, precision, suppress_small)
   1959 
   1960     """
-> 1961     return array2string(a, max_line_width, precision, suppress_small, ' ', "", str)
   1962 
   1963 

C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\arrayprint.py in array2string(a, max_line_width, precision, suppress_small, separator, prefix, style, formatter)
    461     else:
    462         lst = _array2string(a, max_line_width, precision, suppress_small,
--> 463                             separator, prefix, formatter=formatter)
    464     return lst
    465 

C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\arrayprint.py in _array2string(a, max_line_width, precision, suppress_small, separator, prefix, formatter)
    321     else:
    322         summary_insert = ""
--> 323         data = ravel(asarray(a))
    324 
    325     # find the right formatting function for the array

C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\fromnumeric.py in ravel(a, order)
   1463 
   1464     """
-> 1465     if isinstance(a, np.matrix):
   1466         return asarray(a).ravel(order=order)
   1467     else:

TypeError: isinstance() arg 2 must be a type or tuple of types

任何类型的帮助都会很棒。

0 个答案:

没有答案