简体   繁体   English

Python创建一个设置大小的numpy数组

[英]Python create a numpy array of set size

I want to create a numpy array of a set size. 我想创建一个设置大小的numpy数组。 I have a numpy array containing 4 numbers. 我有一个包含4个数字的numpy数组。 My question right now is how to fill the array with zeros till an arbitrary size eg 7 in this example 我现在的问题是如何用零填充数组直到任意大小,例如本例中的7

pos = np.array([1,4,6,8])
new_pos = np.array([1,4,6,8,0,0,0])
np.zeros(5) # returns array([ 0.,  0.,  0.,  0.,  0.])
new_pos = pos.append(np.zeros(5))

5 has been used arbitrarily. 5已被任意使用。 In your case it will be 3. 在您的情况下为3。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM