且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

重复数组并停在特定位置w/numpy

更新时间:2023-02-23 11:16:31

您可以使用 np.resize .

>>> np.resize([1., 2., 3.], 5)
array([ 1., 2., 3., 1., 2.])

此功能自以下日期起生效:

This works since:

如果新数组大于原始数组,则新数组将填充a的重复副本.

If the new array is larger than the original array, then the new array is filled with repeated copies of a.

请注意,np.ndarray.resize 方法具有不同的行为,用零填充(并且对数组进行突变而不是使用新的填充),因此您需要使用函数而不是方法.

Note that the np.ndarray.resize method has different behavior, padding with zeros (and also mutating the array instead of making a new one), so you need to use the function, not the method.