我正在尝试将 numpy array
x = [1,2,3,4]
添加到形状 (n,4)
的numpy数组的"末端"中(即"将 x
推到阵列(,同时删除第一个元素(即" shift"数组(。因此,基本上,在添加我的数组x
之后,应删除最后添加的(4)
形数组。
一个人如何以计算上最有效的方式进行操作?
您正在描述一个环缓冲区。只需使用一个普通的numpy阵列加一个整数,该整数告诉您哪一行是"顶部"。为了推动,只需用新行替换"顶部"行,然后增加顶部索引。