Python numpy.ndarray.resize()
numpy.ndarray.resize()函数在原地改变阵列的形状和大小。
语法: numpy.ndarray.resize(new_shape, refcheck = True)
参数 :
new_shape : [tuple of ints, or n ints] 调整后阵列的形状。
refcheck : [bool, optional] 如果是False,引用计数将不被检查。默认为真。
返回:无
代码#1:
# Python program explaining
# numpy.ndarray.resize() function
# importing numpy as geek
import numpy as geek
arr = geek.array([[0, 1], [2, 3]])
# this function change the shape and size
# of the array & return None
gfg = arr.resize((2, 1))
print (gfg)
输出 :
None
代码#2:
# Python program explaining
# numpy.ndarray.resize() function
# importing numpy as geek
import numpy as geek
arr = geek.array([[0, 1], [2, 3]], order = 'F')
# this function change the shape and size
# of the array & return None
gfg = arr.resize((2, 1))
print (gfg)
输出 :
None