借助Numpy matrix.resize()方法,我们能够调整给定矩阵的形状。请记住,在调整给定矩阵的大小之后,应覆盖所有元素。
用法: matrix.resize(shape)
返回: 新调整大小的矩阵
范例1:
在给定的示例中,我们能够通过使用来调整给定矩阵的大小matrix.resize()方法。
# import the important module in python 
import numpy as np 
           
# make matrix with numpy 
gfg = np.matrix('[64, 1; 12, 3]') 
           
# applying matrix.resize() method 
geeks = gfg.resize((1, 4)) 
     
print(geeks)
输出:
[[64 1 12 3]]
范例2:
# import the important module in python 
import numpy as np 
           
# make a matrix with numpy 
gfg = np.matrix('[1, 2; 4, 5; 7, 8]') 
           
# applying matrix.resize() method 
geeks = gfg.resize((2, 3)) 
     
print(geeks)
输出:
[[1 2 4] [5 7 8]]
相关用法
- Python Numpy numpy.ndarray.__add__()用法及代码示例
 - Python Numpy numpy.ndarray.__sub__()用法及代码示例
 - Python Numpy numpy.ndarray.__mul__()用法及代码示例
 - Python Numpy numpy.ndarray.__truediv__()用法及代码示例
 - Python Numpy numpy.ndarray.__xor__()用法及代码示例
 - Python Numpy numpy.ndarray.__pos__()用法及代码示例
 - Python Numpy numpy.ndarray.__and__()用法及代码示例
 - Python Numpy numpy.ndarray.__neg__()用法及代码示例
 - Python Numpy numpy.ndarray.__isub__()用法及代码示例
 - Python Numpy numpy.ndarray.__rshift__()用法及代码示例
 - Python Numpy numpy.ndarray.__iadd__()用法及代码示例
 - Python Numpy numpy.ndarray.__pow__()用法及代码示例
 - Python Numpy numpy.ndarray.__lshift__()用法及代码示例
 - Python Numpy numpy.ndarray.__divmod__()用法及代码示例
 - Python Numpy numpy.ndarray.__invert__()用法及代码示例
 
注:本文由纯净天空筛选整理自Jitender_1998大神的英文原创作品 Python | Numpy matrix.resize()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
