np.resize
numpy.resize(a, new_shape)a:要被resize的数组new_shape:被resize的大小,int或者tuple类型返回一个特定形状的数组Return a new array with the specified shape.If the new array is larger than the original array, then the new array is
·
numpy.resize(a, new_shape)
- a:要被resize的数组
- new_shape:被resize的大小,int或者tuple类型
返回一个特定形状的数组
Return a new array with the specified shape.
If the new array is larger than the original array, then the new array is filled with repeated copies of a. Note that this behavior is different from a.resize(new_shape) which fills with zeros instead of repeated copies of a.
注意:numpy.resize(a, new_shape)和a.resize(new_shape)方法不同
- 如果new_shape与a相同:二者操作一致,不同处为a.resize为in_place操作
- 如果new_shape与a不同:二者操作不一致,numpy.resize会取a中的元素进行填充,而a.resize会用0进行填充
a = np.array([[0,1], [2,3]])
b = np.resize(a, (3, 3))
print(a)
print(b)
'''
取a中的元素进行填充
[[0 1]
[2 3]]
[[0 1 2]
[3 0 1]
[2 3 0]]
'''
a.resize(3, 3)
print(a)
'''
用0进行填充,并且为in-place操作
[[0 1 2]
[3 0 0]
[0 0 0]]
'''
更多推荐
已为社区贡献11条内容
所有评论(0)