Python numpy.ndarray.resize()

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

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程