Python 一维 numpy 连接:类型错误:只有整数标量数组可以转换为标量索引

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47388013/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 18:11:32  来源:igfitidea点击:

1D numpy concatenate: TypeError: only integer scalar arrays can be converted to a scalar index

pythonarraysnumpy

提问by Santhosh

I want to store numpy array into to another numpy array

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

I am using np.concatenate

我在用 np.concatenate

This is my code

这是我的代码

x=np.concatenate(x,s_x)

These are the type and the shape of x and 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,)

This is the error being displayed

这是正在显示的错误

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

回答by Nils Werner

You need to pass the arrays as an iterable (a tuple or list), thus the correct syntax is

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

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