日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python创建矩阵_在Python中创建矩阵的Python程序

發(fā)布時間:2023/12/1 python 52 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python创建矩阵_在Python中创建矩阵的Python程序 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

python創(chuàng)建矩陣

There is no specific data type in Python to create a matrix, we can use list of list to create a matrix.

Python中沒有特定的數(shù)據(jù)類型來創(chuàng)建矩陣,我們可以使用list列表來創(chuàng)建矩陣 。

Consider the below example,

考慮下面的示例,

mat = [[10, 20, 30],[40, 50, 60],[70, 80, 80] ]

It can be considered a 3x3 matrix, there are 3 rows and 3 columns in 'mat' matrix.

可以認為是3x3矩陣,“ mat”矩陣中有3行3列。

訪問矩陣元素 (Accessing matrix elements)

Just like matrix in C/C++, we can access the elements in Python also.

就像C / C ++中的矩陣一樣,我們也可以訪問Python中的元素。

Consider the below program,

考慮下面的程序,

# Python matrix creation mat = [[10, 20, 30],[40, 50, 60],[70, 80, 80] ]# printing the matrix print("mat: ", mat)# printing rows print("mat[0]: ", mat[0]) print("mat[1]: ", mat[1]) print("mat[2]: ", mat[2])# printing specific elements print("mat[0][0]: ", mat[0][0]) print("mat[0][1]: ", mat[0][1]) print("mat[0][2]: ", mat[0][2]) print("mat[1][0]: ", mat[1][0]) print("mat[1][1]: ", mat[1][1]) print("mat[1][2]: ", mat[1][2]) print("mat[2][0]: ", mat[2][0]) print("mat[2][1]: ", mat[2][1]) print("mat[2][2]: ", mat[2][2])# printing matrix using loop (matrix form) print("Matrix is: ") for i in range(3):for j in range(3):print(mat[i][j], end = " ")print() # prints new line

Output

輸出量

mat: [[10, 20, 30], [40, 50, 60], [70, 80, 80]] mat[0]: [10, 20, 30] mat[1]: [40, 50, 60] mat[2]: [70, 80, 80] mat[0][0]: 10 mat[0][1]: 20 mat[0][2]: 30 mat[1][0]: 40 mat[1][1]: 50 mat[1][2]: 60 mat[2][0]: 70 mat[2][1]: 80 mat[2][2]: 80 Matrix is: 10 20 30 40 50 60 70 80 80

翻譯自: https://www.includehelp.com/python/program-to-create-matrix.aspx

python創(chuàng)建矩陣

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎

總結

以上是生活随笔為你收集整理的python创建矩阵_在Python中创建矩阵的Python程序的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。