python - 与空 numpy 数组连接

标签 python numpy

在 Python 中连接数组时遇到错误:

x = np.array([])
while condition:
    % some processing 
    x = np.concatenate([x + new_x])

我得到的错误是:

----> 1 x = np.concatenate([x + new_x])

ValueError: operands could not be broadcast together with shapes (0) (6) 

顺便说一句,这是在 Python 中增长 numpy 数组的有效方法吗?

最佳答案

看起来您想打电话

x = np.concatenate((x, new_x))

根据the docs .

关于python - 与空 numpy 数组连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13729322/

相关文章:

Python 安装脚本扩展,如何包含 .h 文件?

python - 运行时警告 : invalid value encountered in double_scalars related to np. sqrt

python - scipy.signal.spectrogram nfft 参数

python - 如何在 Windows 和 Linux 上使用相同的 Python virtualenv

python - 将生菜与 TeamCity 集成

python - 使用 ManyToManyField 时出现重复字段

python - 使用 range() 或 slice() 对二维 ndarray 进行切片的区别

python - scikit-learn "scoring must return a number"cross_val_score 错误

python - 在 python 中 a/= 2.0 和 a = a/2.0 的结果是不一样的

python - 仅在赋值时如何实现嵌套字典的自动生成?