将值插入到空的多维中. numpy数组 [英] Inserting values to an empty multidim. numpy array
本文介绍了将值插入到空的多维中. numpy数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要创建一个形状为(?, 10, 10, 3)
的空numpy数组. ?
表示我不知道要插入多少个元素.然后,我想将许多形状为(1, 10, 10, 3)
的numpy数组一一插入到准备好的数组中,因此?
标记将随着插入的元素而增加.
I need to create an empty numpy array of a shape (?, 10, 10, 3)
. ?
means I don't know how many elements will be inserted. Then I have many numpy arrays of a shape (1, 10, 10, 3)
which I want to be inserted to the prepared array one by one, so the ?
mark will be increasing with inserted elements.
我正在尝试numpy数组方法的所有变体,例如empty
,insert
,concatenate
,append
...,但是我无法实现.你能帮我个忙吗?
I'm trying all variations of numpy array methods like empty
, insert
, concatenate
, append
... but I'm not able to achieve this. Could you please give me a hand with this?
推荐答案
Using np.append
works:
import numpy as np
mat = np.empty((0,10,10,3))
array = np.random.rand(1,10,10,3)
mat = np.append(mat, array, axis=0)
mat = np.append(mat, array, axis=0)
print(mat.shape)
>>>(2,10,10,3)
这篇关于将值插入到空的多维中. numpy数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文