return _nx.concatenate(expanded_arrays, axis=axis, out=out) File "<__array_function__ internals>", line 180, in concatenate numpy.core._exceptions._ArrayMemoryError: Unable to allocate 3.67 GiB for an array with shape (16, 3, 4530, 4530) and data type float32
时间: 2023-06-08 13:05:35 浏览: 109
看起来您在尝试使用numpy中的concatenate函数将几个数组合并成一个大数组,但是由于内存错误,无法分配足够的内存来创建这个大数组。您可以尝试减少数组的数量或大小,或者增加系统内存以解决此问题。
相关问题
Traceback (most recent call last): File "D:/pycharm/projects/Pythoneeee/projects/d.py", line 65, in <module> coef_mat = np.column_stack((prob_fit.theta_.T, logit_fit.coef_, linear_fit.coef_)) # File "<__array_function__ internals>", line 200, in column_stack File "D:\pycharm\projects\venv\lib\site-packages\numpy\lib\shape_base.py", line 656, in column_stack return _nx.concatenate(arrays, 1) File "<__array_function__ internals>", line 200, in concatenate ValueError: all the input array dimensions except for the concatenation axis must match exactly, but along dimension 0, the array at index 0 has size 10 and the array at index 1 has size 1
这个错误提示是因为`prob_fit.theta_`的维度是`(1, n)`,而`logit_fit.coef_`和`linear_fit.coef_`的维度是`(1,)`和`(1, m)`,所以无法直接进行列合并。可以使用`np.squeeze`方法将`prob_fit.theta_`的维度压缩成`(n,)`,然后再进行列合并。具体代码如下:
```python
prob_theta = np.squeeze(prob_fit.theta_)
coef_mat = np.column_stack((prob_theta, logit_fit.coef_[0], linear_fit.coef_[0]))
```
这里的`np.squeeze`方法可以将维度为1的维度压缩掉,即将`(1, n)`的矩阵转换成`(n,)`的向量。
File "D:/pycharm/projects/Pythoneeee/projects/d.py", line 65, in <module> coef_mat = np.column_stack((prob_theta, logit_fit.coef_[0], linear_fit.coef_[0])) File "<__array_function__ internals>", line 200, in column_stack File "D:\pycharm\projects\venv\lib\site-packages\numpy\lib\shape_base.py", line 656, in column_stack return _nx.concatenate(arrays, 1) File "<__array_function__ internals>", line 200, in concatenate ValueError: all the input array dimensions except for the concatenation axis must match exactly, but along dimension 0, the array at index 0 has size 2 and the array at index 1 has size 10
这个错误提示是因为`prob_theta`和`logit_fit.coef_[0]`的维度不一致导致的。可以将`prob_theta`转换成`(n,1)`的矩阵,然后再进行列合并,这样就能保证每个数组在第0个维度上的长度一致了。具体代码如下:
```python
prob_theta = prob_theta.reshape(-1, 1)
coef_mat = np.column_stack((prob_theta, logit_fit.coef_[0], linear_fit.coef_[0]))
```
这里的`reshape`方法将`prob_theta`转换成`(n,1)`的矩阵,其中`-1`表示自动计算维度大小,因为我们只需要将行数确定为`n`即可。
阅读全文