使用 Numpy 查找给定矩阵中的行数和列数
pythonnumpyprogrammingserver side programming更新于 2024/9/21 17:16:17
我们将首先创建一个 numpy 矩阵,然后找出该矩阵中的行数和列数
算法
步骤 1:创建一个随机数的 numpy 矩阵。 步骤 2:使用 numpy.shape 函数查找矩阵的行数和列数。 步骤 3:打印行数和列数。
示例代码
import numpy as np
matrix = np.random.rand(2,3)
print(matrix)
print("Total number of rows and columns in the given matrix are: ", matrix.shape)
输出
[[0.23226052 0.89690884 0.19813164] [0.85170808 0.97725669 0.72454096]] Total number of rows and columns in the given matrix are: (2, 3)
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

