使用 Numpy 查找指定矩阵中行和列的数量
我们首先创建一个 numpy 矩阵,然后找出该矩阵中的行数和列数。
算法
Step 1: Create a numpy matrix of random numbers. Step 2: Find the rows and columns of the matrix using numpy.shape function. Step 3: Print the number of rows and columns.
示例代码
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)
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP