使用 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)

更新日期:16-Mar-2021

3K+ 瀏覽量

開啟你的 職業生涯

完成課程,獲得認證

開始
廣告
© . All rights reserved.