单个元素添加到数组numpy的 [英] Add single element to array in numpy
本文介绍了单个元素添加到数组numpy的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含numpy的数组:
I have a numpy array containing:
[1, 2, 3]
我要创建一个包含数组:
I want to create an array containing:
[1, 2, 3, 1]
即,我要添加到数组的末尾的第一个元素
That is, I want to add the first element on to the end of the array.
我已经尝试了很明显的:
I have tried the obvious:
np.concatenate((a, a[0]))
不过,我得到一个错误说 ValueError错误:数组必须具有相同的维数
我不明白这一点 - 阵列都只有一维数组
I don't understand this - the arrays are both just 1d arrays.
推荐答案
我认为这是比较正常的使用适当的方法添加元素:
I think it's more normal to use the proper method for adding an element:
numpy.append(a, a[0])
这篇关于单个元素添加到数组numpy的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文