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 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]]
'''
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值