Python Numpy matrix.resize()

Python Numpy matrix.resize()

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教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程