【问题标题】:1D numpy concatenate: TypeError: only integer scalar arrays can be converted to a scalar index [duplicate]一维numpy连接:TypeError:只能将整数标量数组转换为标量索引[重复]
【发布时间】:2018-05-03 10:27:54
【问题描述】:

我想将 numpy 数组存储到另一个 numpy 数组中

我正在使用np.concatenate

这是我的代码

x=np.concatenate(x,s_x)

这些是x and s_x的类型和形状

Type of s_x: <class 'numpy.ndarray'>, Shape of s_x: (173,)
Type of x: <class 'numpy.ndarray'> (0,), Shape of x: (0,)

这是显示的错误

TypeError: only integer scalar arrays can be converted to a scalar index

【问题讨论】:

    标签: python arrays numpy


    【解决方案1】:

    您需要将数组作为可迭代对象(元组或列表)传递,因此正确的语法是

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

    【讨论】:

    • 对于这样一个常见且有用的功能,它确实有最无用的错误消息。谢谢!
    • Python 很棒,但正是这种吹毛求疵的方式有时让人头疼。
    • 我很幸运能够向下滚动谷歌搜索结果并找到这个答案。
    • @UlissesBraga-Neto 问题不在于 Python,而在于 numpy。错误消息应该提供更多信息。
    猜你喜欢
    • 2020-04-30
    • 2020-07-23
    • 2021-02-09
    • 2021-10-31
    • 2019-03-15
    • 2018-04-04
    • 2020-09-24
    • 2019-01-09
    • 2018-09-27
    相关资源
    最近更新 更多