Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python LinalError:给定了0维数组。数组必须至少是二维的_Python_Arrays_Numpy - Fatal编程技术网

Python LinalError:给定了0维数组。数组必须至少是二维的

Python LinalError:给定了0维数组。数组必须至少是二维的,python,arrays,numpy,Python,Arrays,Numpy,我得到了上面的错误,错误消息抱怨0维数组 ------------------------------------------------------------------- -------- LinAlgError Traceback (most recent call last) <ipython-input-110-2e59b52b853b> in <module>() 8 9 # c

我得到了上面的错误,错误消息抱怨0维数组

   -------------------------------------------------------------------  --------
LinAlgError                               Traceback (most recent call  last)
<ipython-input-110-2e59b52b853b> in <module>()
  8 
  9 # compute det and C_N
---> 10 const = np.sqrt(np.linalg.det((dof-2)/dof)*C_N)
 11 print(const)

<__array_function__ internals> in det(*args, **kwargs)

/anaconda3/lib/python3.6/site-packages/numpy/linalg/linalg.py in  det(a)
2110     """
2111     a = asarray(a)
-> 2112     _assert_stacked_2d(a)
2113     _assert_stacked_square(a)
2114     t, result_t = _commonType(a)

/anaconda3/lib/python3.6/site-packages/numpy/linalg/linalg.py in _assert_stacked_2d(*arrays)
205         if a.ndim < 2:
206             raise LinAlgError('%d-dimensional array given. Array  must be '
--> 207                     'at least two-dimensional' % a.ndim)
208 
209 def _assert_stacked_square(*arrays):

LinAlgError: 0-dimensional array given. Array must be at least two-dimensional

非常感谢那些关心并敢于通读这一切的无畏者。

(dof-2)/dof
是一个标量。它没有行列式,
C\N
似乎也是一个标量……好的,非常感谢你,我意识到其中两个是标量
import numpy as np
npts = 5000
dof  = 3
X_r = np.arange(npts)
product = X_r * X_r.transpose()  
Rowsum = [np.sum(product[i]) for i in range(npts)]
C_N = np.sum(Rowsum)/(npts - 1)

 # compute det and C_N 
const = np.sqrt(np.linalg.det(((dof-2)/dof)*C_N))
print(const)