Chương trình Python ma trận

Chúng ta có thể dễ dàng thực hiện thao tác ma trận trong Python bằng thư viện Numpy. NumPy là một gói Python. Nó là viết tắt của 'Python số'. Nó là một thư viện bao gồm các đối tượng mảng đa chiều và một tập hợp các thủ tục để xử lý mảng. Sử dụng NumPy, các phép toán và logic trên mảng có thể được thực hiện

Cài đặt và nhập Numpy

Để cài đặt Numpy, hãy sử dụng pip -

pip install numpy

Nhập Numpy −

import numpy

Cộng, trừ, chia và nhân ma trận

Chúng tôi sẽ sử dụng các phương thức Numpy sau đây để thao tác với ma trận

  • cục mịch. add[] - Cộng hai ma trận

  • cục mịch. trừ[] - Trừ hai ma trận

  • cục mịch. chia [] - Chia hai ma trận

  • cục mịch. multi[] - Nhân hai ma trận

Bây giờ chúng ta hãy xem mã

Ví dụ

đầu ra

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]

Tổng các phần tử ma trận

Phương thức sum[] được sử dụng để tìm tổng -

Ví dụ

đầu ra

Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]

Chuyển đổi từ ma trận

Các. Thuộc tính T được sử dụng để tìm Chuyển vị của Ma trận −

Ví dụ

đầu ra

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]

Python được biết đến với tính năng xử lý và đọc dữ liệu rõ ràng và gọn gàng. Có nhiều kỹ thuật khác nhau để xử lý dữ liệu trong Python như sử dụng Từ điển, Bộ dữ liệu, Ma trận, v.v. Trong hướng dẫn này, bạn sẽ tìm hiểu về ma trận và các chức năng của nó

Ma trận trong Python là gì?

Đây là những cấu trúc dữ liệu 2D [hai chiều]. Trong các dự án trực tiếp và mô phỏng dữ liệu thực, bạn phải giữ dữ liệu ở định dạng tuần tự hoặc dạng bảng. Giả sử bạn muốn lưu trữ dữ liệu của ba nhân viên thuộc ba phòng ban khác nhau. Vì vậy, ở định dạng của các bảng, nó sẽ trông giống như

ID nhân viênTên nhân viênPhòng nhân viên1001ARayTrưởng phòng kỹ thuật2004BKarlosManager3100AAlexLead Developer

Trong Python, các bảng này được gọi là mảng hai chiều, còn được gọi là ma trận. Python cung cấp cho chúng tôi cơ sở để biểu diễn những dữ liệu này dưới dạng danh sách

Ví dụ

val = [['1001A','Ray', 'Technical Head'], ['2004B', 'Karlos' , 'Manager'], ['3100A', 'Alex' , 'Lead Developer']]

Trong đoạn mã trên, val đại diện cho ma trận 3 X 3 trong đó có ba hàng và ba cột

Tạo một ma trận trong Python

Python cho phép các nhà phát triển triển khai ma trận bằng cách sử dụng danh sách lồng nhau. Danh sách có thể được tạo nếu bạn đặt tất cả các mục hoặc thành phần bắt đầu bằng '[' và kết thúc bằng ']' [dấu ngoặc vuông] và phân tách từng thành phần bằng dấu phẩy

val = [['Dave',101,90,95],

['Alex',102,85,100],

['Ray',103,90,95]]

Tự động tạo ma trận trong Python

Có thể tạo ma trận n x m bằng cách liệt kê một tập hợp các phần tử [giả sử n] và sau đó làm cho mỗi phần tử được liên kết với một danh sách 1D khác gồm m phần tử. Đây là một đoạn mã cho điều này

n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]

Đầu ra của chương trình sẽ là

________số 8

Truy cập các phần tử của ma trận

Có nhiều phương pháp khác nhau để lấy các phần tử của ma trận trong Python

i] Chỉ mục. Để truy cập các phần tử của ma trận, bạn phải sử dụng dấu ngoặc vuông sau tên biến với số hàng và cột, như thế này val[row_no][col_no]

val = [['Dave',101,90,95], ['Alex',102,85,100], ['Ray',103,90,95]]

print[val[2]]

print[val[0][1]]

đầu ra

import numpy
0

ii] Lập chỉ mục tiêu cực. Python cũng cung cấp tính năng lập chỉ mục với các giá trị âm trong dấu ngoặc vuông của nó để truy cập các giá trị một cách tuần tự. Trong lập chỉ mục phủ định, -1 đề cập đến phần tử cuối cùng của ma trận, -2 là phần tử cuối cùng thứ 2 và tiếp tục

Ở đây chúng ta sẽ thảo luận về các cách khác nhau để tạo ma trận bằng Python trong hướng dẫn này, chúng ta cũng sẽ thảo luận về các thao tác khác nhau có thể được thực hiện trên ma trận. chúng tôi cũng sẽ đề cập đến mô-đun bên ngoài Numpy để tạo ma trận và các hoạt động của nó trong Python

 

Ma trận là gì?

Ma trận là tập hợp các số được sắp xếp trong một mảng hình chữ nhật theo hàng và cột. Trong các lĩnh vực kỹ thuật, vật lý, thống kê và đồ họa, ma trận được sử dụng rộng rãi để thể hiện phép quay ảnh và các loại phép biến đổi khác.
Ma trận được gọi là ma trận m nhân n, được ký hiệu bằng ký hiệu "m x n" nếu có m hàng, n cột.

Tạo một ma trận đơn giản bằng Python

Phương pháp 1. Tạo ma trận với Danh sách danh sách

Ở đây, chúng ta sẽ tạo một ma trận bằng cách sử dụng danh sách các danh sách

Python3




import numpy
19
import numpy
20
import numpy
21_______122
import numpy
23
import numpy
24
import numpy
23
import numpy
26
import numpy
23
import numpy
28
import numpy
29

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
20
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
21____222
import numpy
23
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
24
import numpy
23
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
26
import numpy
23
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
28
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
29

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
20
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
21____342
import numpy
23
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
44
import numpy
23______346
import numpy
23
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
48
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
49

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

_______421____422____423

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
24

đầu ra

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
7

Phương pháp 2. Lấy đầu vào Ma trận từ người dùng trong Python

Ở đây, chúng tôi đang lấy một số hàng và cột từ người dùng và in Ma trận

Python3




Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
25
import numpy
20
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
27
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
22
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
29
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
22____541
val = [['1001A','Ray', 'Technical Head'], ['2004B', 'Karlos' , 'Manager'], ['3100A', 'Alex' , 'Lead Developer']]
42

val = [['1001A','Ray', 'Technical Head'], ['2004B', 'Karlos' , 'Manager'], ['3100A', 'Alex' , 'Lead Developer']]
43
import numpy
20
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
27
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
22
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
29
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
22
val = [['1001A','Ray', 'Technical Head'], ['2004B', 'Karlos' , 'Manager'], ['3100A', 'Alex' , 'Lead Developer']]
49
val = [['1001A','Ray', 'Technical Head'], ['2004B', 'Karlos' , 'Manager'], ['3100A', 'Alex' , 'Lead Developer']]
42

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

val = [['Dave',101,90,95],

['Alex',102,85,100],

['Ray',103,90,95]]
52

import numpy
19
import numpy
20
val = [['Dave',101,90,95],

['Alex',102,85,100],

['Ray',103,90,95]]
55

_______421____422____658

val = [['Dave',101,90,95],

['Alex',102,85,100],

['Ray',103,90,95]]
59

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
41

n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
42

n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
43
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
44
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
45
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
46
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
47

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
20
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
49
import numpy
20
val = [['Dave',101,90,95],

['Alex',102,85,100],

['Ray',103,90,95]]
55

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
20
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
63

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
20
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
43
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
66
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
45
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
46
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
69

import numpy
100
import numpy
101
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
27______422
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
29
import numpy
105

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
20
import numpy
107

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

import numpy
109

n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
43
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
44
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
45
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
46
import numpy
114

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
20
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
43
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
66
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
45
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
46
import numpy
120

import numpy
100
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
21
import numpy
123
import numpy
20
import numpy
125
val = [['Dave',101,90,95],

['Alex',102,85,100],

['Ray',103,90,95]]
59

_______220____421____1129

đầu ra

import numpy
1

Phương pháp 3. Tạo một ma trận bằng cách sử dụng hiểu danh sách

Hiểu danh sách là một cách hay để xác định và tạo danh sách trong Python, chúng tôi đang sử dụng hàm phạm vi để in 4 hàng và 4 cột

Python3




import numpy
19
import numpy
20
import numpy
132_______743
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
66
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
45
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
46
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
22
import numpy
28
import numpy
139
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
43
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
44
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
45
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
46
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
22
import numpy
28
import numpy
139

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

_______421____1149

đầu ra

import numpy
2

Gán giá trị trong ma trận

Phương pháp 1. Gán một giá trị cho một ô riêng lẻ trong Ma trận

Ở đây chúng tôi đang thay thế và gán giá trị cho một ô riêng lẻ [1 hàng và 1 cột = 11] trong Ma trận

Python3




import numpy
150
import numpy
20
import numpy
21
import numpy
22
import numpy
23
import numpy
24_______123
import numpy
26
import numpy
158
import numpy
28
import numpy
23
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
22
import numpy
23
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
24
import numpy
158
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
26
import numpy
23
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
28
import numpy
23
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
42
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
49

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
44
import numpy
20
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
66
import numpy
20
import numpy
22

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

import numpy
178
import numpy
20
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
46

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

_______421____1183

đầu ra

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
2

Phương pháp 2. Gán một giá trị cho một ô riêng lẻ bằng cách sử dụng lập chỉ mục phủ định trong Ma trận

Ở đây chúng tôi đang thay thế và gán giá trị cho một ô riêng lẻ [-2 hàng và -1 cột = 21] trong Ma trận

Python3




n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
44
import numpy
20
import numpy
186
import numpy
24

[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
66
import numpy
20
import numpy
186
import numpy
22

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

import numpy
178
import numpy
20
import numpy
195

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

_______421____1183

đầu ra

Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
4

Truy cập giá trị trong một ma trận

Phương pháp 1. Truy cập các giá trị Ma trận

Ở đây, chúng tôi đang truy cập các phần tử của Ma trận bằng cách chuyển hàng và cột của nó

Python3




Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
21
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
22
import numpy
201
import numpy
202
import numpy
203
import numpy
204
import numpy
24
import numpy
206

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
21
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
22
import numpy
209
import numpy
202
import numpy
24
import numpy
204
import numpy
24
import numpy
214

đầu ra

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
2

Phương pháp 2. Truy cập các giá trị Ma trận bằng cách sử dụng chỉ mục tiêu cực

Ở đây, chúng tôi đang truy cập các phần tử của Ma trận bằng cách chuyển hàng và cột của nó vào chỉ mục phủ định

Python3




import numpy
215
import numpy
216

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

import numpy
150
import numpy
20
import numpy
21
import numpy
22
import numpy
23
import numpy
24_______123
import numpy
26
import numpy
158
import numpy
28
import numpy
23
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
22
import numpy
23
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
24
import numpy
158
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
26
import numpy
23
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
28
import numpy
23
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
42
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
49

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
21
import numpy
241
import numpy
186
import numpy
22
import numpy
204
import numpy
186
import numpy
24
import numpy
214

đầu ra

val = [['1001A','Ray', 'Technical Head'], ['2004B', 'Karlos' , 'Manager'], ['3100A', 'Alex' , 'Lead Developer']]
4

Các phép toán với ma trận trong Python

ví dụ 1. Thêm giá trị vào ma trận với vòng lặp for trong python

Ở đây, chúng tôi đang thêm hai ma trận bằng cách sử dụng vòng lặp for của Python

Python3




import numpy
248

import numpy
150
import numpy
20
import numpy
21
import numpy
22
import numpy
23
import numpy
24_______123
import numpy
26
import numpy
257
import numpy
28
import numpy
23
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
22
import numpy
23
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
24
import numpy
158
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
26
import numpy
23
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
28
import numpy
23
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
42
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
49

import numpy
270
import numpy
20
import numpy
21
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
42
import numpy
23
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
28_______123
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
26
import numpy
158
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
24
import numpy
23
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
22
import numpy
23
import numpy
28
import numpy
158
import numpy
26
import numpy
23
import numpy
24
import numpy
23
import numpy
22
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
49

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

import numpy
292
import numpy
20
import numpy
21
import numpy
203
import numpy
23
import numpy
203
import numpy
23
import numpy
203
import numpy
158
import numpy
203
import numpy
23
import numpy
203
import numpy
23
import numpy
203
import numpy
158
import numpy
203
import numpy
23
import numpy
203
import numpy
23
import numpy
203
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
49

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
214

n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
43
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
44
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
45
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
46
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
22
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
220
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
221

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
20
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
224

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
20
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
43
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
66
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
45
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
46
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
22
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
220
import numpy
241
import numpy
203
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
234

import numpy
100
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
236
import numpy
20
import numpy
178
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
239
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
240

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
43
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
243____745
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
245

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
20____421____2248

đầu ra

val = [['Dave',101,90,95],

['Alex',102,85,100],

['Ray',103,90,95]]
5

ví dụ 2. Cộng và trừ các giá trị vào ma trận với khả năng hiểu danh sách

Thực hiện phép cộng và phép trừ cơ bản bằng cách sử dụng khả năng hiểu danh sách

Python3




Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
249
import numpy
20
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
251____2239
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
240

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
254
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
43
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
66
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
45
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
46
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
22____2220
import numpy
241
import numpy
203
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
263

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
254
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
43
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
44
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
45
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
46
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
22
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
220
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
271

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
272
import numpy
20
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
251____1186
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
240

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
254
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
43
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
66
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
45
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
46
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
22____2220
import numpy
241
import numpy
203
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
263

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
254
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
43
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
44
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
45
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
46
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
22
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
220
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
271

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

_______421____422____2298

val = [['Dave',101,90,95],

['Alex',102,85,100],

['Ray',103,90,95]]
59

n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
43
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
243____745
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
403

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
20____421____2248

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

_______421____422____3410

val = [['Dave',101,90,95],

['Alex',102,85,100],

['Ray',103,90,95]]
59

n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
43
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
243____745
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
415

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
20____421____2248

đầu ra

n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
4

ví dụ 3. Chương trình Python để nhân và chia hai ma trận

Thực hiện phép nhân và chia cơ bản bằng vòng lặp Python

Python3




Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
419
import numpy
20
import numpy
21
import numpy
203
import numpy
23
import numpy
203
import numpy
23
import numpy
203
import numpy
158
import numpy
203
import numpy
23
import numpy
203
import numpy
23
import numpy
203
import numpy
158
import numpy
203
import numpy
23
import numpy
203
import numpy
23
import numpy
203
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
49

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
43
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
44
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
45
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
46
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
22
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
220
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
221

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
20
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
43
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
66
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
45
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
46
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
22
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
220
import numpy
241
import numpy
203
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
234

import numpy
100
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
459
import numpy
20
import numpy
178
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
462
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
240

Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
464

_______421____422____3467

Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
468

n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
43
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
243____745
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
472

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
20____421____2248

Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
464

n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
43
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
478
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
45
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
46
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
22
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
220____2221

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
20
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
43
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
486
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
45
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
46
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
22
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
220
import numpy
241
import numpy
203
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
234

import numpy
100
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
459
import numpy
20
import numpy
178
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
498
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
498
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
240

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

_______421____422____4204

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
205

n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
43
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
243____745
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
472

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
20____421____2248

đầu ra

[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
6

Hoán vị trong ma trận

Ví dụ. Chương trình Python để chuyển vị ma trận bằng vòng lặp

Chuyển vị của ma trận có được bằng cách thay đổi hàng thành cột và cột thành hàng. Nói cách khác, chuyển vị của A[][] có được bằng cách thay đổi A[i][j] thành A[j][i]

Python3




import numpy
150
import numpy
20
import numpy
21
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
42
import numpy
23
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
28
import numpy
23
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
26
import numpy
158
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
24
import numpy
23
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
22
import numpy
23
import numpy
28
import numpy
158
import numpy
26
import numpy
23
import numpy
24
import numpy
23
import numpy
22
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
49

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

import numpy
292
import numpy
20
import numpy
21
import numpy
203
import numpy
23
import numpy
203
import numpy
23
import numpy
203
import numpy
158
import numpy
203
import numpy
23
import numpy
203
import numpy
23
import numpy
203
import numpy
158
import numpy
203
import numpy
23
import numpy
203
import numpy
23
import numpy
203
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
49

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
214

n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
43
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
44
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
45
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
46
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
22
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
220
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
221

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
20
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
224

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
20
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
43
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
66
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
45
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
46
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
22
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
220
import numpy
241
import numpy
203
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
234

import numpy
100
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
278
import numpy
20
import numpy
178

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
43
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
243____745
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
245

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
20____421____2248

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
289

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
290

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
292

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
293

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
295

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
296

đầu ra

import numpy
10

Ma trận sử dụng Numpy

Tạo ma trận bằng Numpy

Ở đây chúng tôi đang tạo một mảng Numpy bằng cách sử dụng numpy. ngẫu nhiên và một mô-đun ngẫu nhiên

Python3




import numpy
215
import numpy
216

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
299

val = [['1001A','Ray', 'Technical Head'], ['2004B', 'Karlos' , 'Manager'], ['3100A', 'Alex' , 'Lead Developer']]
400

val = [['1001A','Ray', 'Technical Head'], ['2004B', 'Karlos' , 'Manager'], ['3100A', 'Alex' , 'Lead Developer']]
401

val = [['1001A','Ray', 'Technical Head'], ['2004B', 'Karlos' , 'Manager'], ['3100A', 'Alex' , 'Lead Developer']]
402
import numpy
20
val = [['1001A','Ray', 'Technical Head'], ['2004B', 'Karlos' , 'Manager'], ['3100A', 'Alex' , 'Lead Developer']]
404
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
44
val = [['1001A','Ray', 'Technical Head'], ['2004B', 'Karlos' , 'Manager'], ['3100A', 'Alex' , 'Lead Developer']]
406
import numpy
20
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
22
import numpy
26
import numpy
23
import numpy
26
val = [['1001A','Ray', 'Technical Head'], ['2004B', 'Karlos' , 'Manager'], ['3100A', 'Alex' , 'Lead Developer']]
42

_______421____5414

đầu ra

import numpy
11

Các phép toán ma trận trong Python Sử dụng Numpy

Ở đây chúng tôi đang đề cập đến các phép toán khác nhau như cộng, trừ, nhân và chia bằng Numpy

Python3




val = [['1001A','Ray', 'Technical Head'], ['2004B', 'Karlos' , 'Manager'], ['3100A', 'Alex' , 'Lead Developer']]
415

val = [['1001A','Ray', 'Technical Head'], ['2004B', 'Karlos' , 'Manager'], ['3100A', 'Alex' , 'Lead Developer']]
416
import numpy
20
val = [['1001A','Ray', 'Technical Head'], ['2004B', 'Karlos' , 'Manager'], ['3100A', 'Alex' , 'Lead Developer']]
418
import numpy
22
import numpy
23
import numpy
24_______1158
import numpy
28
import numpy
23
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
22
val = [['1001A','Ray', 'Technical Head'], ['2004B', 'Karlos' , 'Manager'], ['3100A', 'Alex' , 'Lead Developer']]
426

val = [['1001A','Ray', 'Technical Head'], ['2004B', 'Karlos' , 'Manager'], ['3100A', 'Alex' , 'Lead Developer']]
427
import numpy
20
val = [['1001A','Ray', 'Technical Head'], ['2004B', 'Karlos' , 'Manager'], ['3100A', 'Alex' , 'Lead Developer']]
418
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
26
import numpy
23
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
28______1158
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
42
import numpy
23
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
44
val = [['1001A','Ray', 'Technical Head'], ['2004B', 'Karlos' , 'Manager'], ['3100A', 'Alex' , 'Lead Developer']]
426

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

val = [['1001A','Ray', 'Technical Head'], ['2004B', 'Karlos' , 'Manager'], ['3100A', 'Alex' , 'Lead Developer']]
439

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
21
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
22____5442
val = [['Dave',101,90,95],

['Alex',102,85,100],

['Ray',103,90,95]]
59

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
21
val = [['1001A','Ray', 'Technical Head'], ['2004B', 'Karlos' , 'Manager'], ['3100A', 'Alex' , 'Lead Developer']]
445

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

val = [['1001A','Ray', 'Technical Head'], ['2004B', 'Karlos' , 'Manager'], ['3100A', 'Alex' , 'Lead Developer']]
447

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
21
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
22____5450
val = [['Dave',101,90,95],

['Alex',102,85,100],

['Ray',103,90,95]]
59

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
21
val = [['1001A','Ray', 'Technical Head'], ['2004B', 'Karlos' , 'Manager'], ['3100A', 'Alex' , 'Lead Developer']]
453

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
21
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
22____5457____659

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
21
val = [['1001A','Ray', 'Technical Head'], ['2004B', 'Karlos' , 'Manager'], ['3100A', 'Alex' , 'Lead Developer']]
460

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

val = [['1001A','Ray', 'Technical Head'], ['2004B', 'Karlos' , 'Manager'], ['3100A', 'Alex' , 'Lead Developer']]
462

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
21
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
22____5465
val = [['Dave',101,90,95],

['Alex',102,85,100],

['Ray',103,90,95]]
59

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
21
val = [['1001A','Ray', 'Technical Head'], ['2004B', 'Karlos' , 'Manager'], ['3100A', 'Alex' , 'Lead Developer']]
468

đầu ra

import numpy
12

Chấm và chéo sản phẩm với Matrix

Ở đây, chúng ta sẽ tìm các tích bên trong, bên ngoài và chéo của ma trận và vectơ bằng cách sử dụng NumPy trong Python

Python3




import numpy
150
import numpy
20
import numpy
21
import numpy
22
import numpy
23
import numpy
24_______123
import numpy
26
import numpy
257
import numpy
28
import numpy
23
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
22
import numpy
23
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
24
import numpy
257
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
26
import numpy
23
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
28
import numpy
23
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
42
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
49

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

import numpy
270
import numpy
20
import numpy
21
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
42
import numpy
23
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
28_______123
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
26
import numpy
158
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
24
import numpy
23
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
22
import numpy
23
import numpy
28
import numpy
257
import numpy
26
import numpy
23
import numpy
24
import numpy
23
import numpy
22
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
49

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

val = [['Dave',101,90,95],

['Alex',102,85,100],

['Ray',103,90,95]]
513
import numpy
20
val = [['Dave',101,90,95],

['Alex',102,85,100],

['Ray',103,90,95]]
515

_______421____422____6518

val = [['Dave',101,90,95],

['Alex',102,85,100],

['Ray',103,90,95]]
519

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

val = [['Dave',101,90,95],

['Alex',102,85,100],

['Ray',103,90,95]]
513
import numpy
20
val = [['Dave',101,90,95],

['Alex',102,85,100],

['Ray',103,90,95]]
523

_______421____422____6526

val = [['Dave',101,90,95],

['Alex',102,85,100],

['Ray',103,90,95]]
519

đầu ra

import numpy
13

Chuyển đổi ma trận trong Python bằng Numpy

Để thực hiện thao tác chuyển vị trên ma trận, chúng ta có thể sử dụng hàm numpy. phương thức chuyển vị[]

Python3




import numpy
19
import numpy
20
import numpy
21_______122
import numpy
23
import numpy
24
import numpy
23
import numpy
26
import numpy
158
import numpy
28
import numpy
23
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
22
import numpy
23
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
24
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
49

_______421____422____6545

val = [['Dave',101,90,95],

['Alex',102,85,100],

['Ray',103,90,95]]
546

đầu ra

import numpy
14

Tạo một ma trận trống với NumPy trong Python

Khởi tạo một mảng trống, sử dụng lệnh np. số không[]

Python3




n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
49
import numpy
20
val = [['Dave',101,90,95],

['Alex',102,85,100],

['Ray',103,90,95]]
549
import numpy
24
import numpy
23
import numpy
24
val = [['Dave',101,90,95],

['Alex',102,85,100],

['Ray',103,90,95]]
553
import numpy
20
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
27
val = [['Dave',101,90,95],

['Alex',102,85,100],

['Ray',103,90,95]]
59

_______421____422____6559

val = [['Dave',101,90,95],

['Alex',102,85,100],

['Ray',103,90,95]]
560

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

val = [['Dave',101,90,95],

['Alex',102,85,100],

['Ray',103,90,95]]
562
import numpy
20
val = [['Dave',101,90,95],

['Alex',102,85,100],

['Ray',103,90,95]]
549
import numpy
26
import numpy
23
import numpy
26
import numpy
214

_______421____422____6571

val = [['Dave',101,90,95],

['Alex',102,85,100],

['Ray',103,90,95]]
572

đầu ra

import numpy
15

Cắt ma trận bằng Numpy

Cắt lát là quá trình chọn các hàng và cột cụ thể từ một ma trận, sau đó tạo một ma trận mới bằng cách loại bỏ tất cả các phần tử không được chọn. Trong ví dụ đầu tiên, chúng tôi đang in toàn bộ ma trận, trong lần thứ hai, chúng tôi chuyển 2 làm chỉ mục ban đầu, 3 làm chỉ mục cuối cùng và chỉ mục nhảy thành 1. Điều tương tự cũng được sử dụng trong bản in tiếp theo, chúng tôi vừa thay đổi bước nhảy chỉ mục thành 2

Python3




import numpy
150
import numpy
20
val = [['Dave',101,90,95],

['Alex',102,85,100],

['Ray',103,90,95]]
575
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
24
import numpy
23
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
28
import numpy
23
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
44
import numpy
29

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
20
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
21____342
import numpy
23
import numpy
186
Matrix =
 [[ 5 10]
 [15 20]]

The summation of elements=
50

The column wise summation=
[20 30]

The row wise summation=
[15 35]
48
import numpy
23
val = [['Dave',101,90,95],

['Alex',102,85,100],

['Ray',103,90,95]]
589
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
29

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
20
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
21____348
import numpy
23______6595
import numpy
23____6597
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
29

Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
20
Matrix1 =
 [[ 5 10]
 [15 20]]

Matrix2 =
[[25 30]
 [35 40]]

Addition of two matrices:
[[30 40]
 [50 60]]

Subtraction of two matrices:
[[-20 -20]
 [-20 -20]]

Matrix Division:
[[0.2 0.33333333]
 [0.42857143 0.5 ]]

Multiplication of two matrices:
[[125 300]
 [525 800]]
21____6589
import numpy
23
import numpy
186
val = [['Dave',101,90,95],

['Alex',102,85,100],

['Ray',103,90,95]]
597
import numpy
23
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
406
val = [['1001A','Ray', 'Technical Head'], ['2004B', 'Karlos' , 'Manager'], ['3100A', 'Alex' , 'Lead Developer']]
426

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
409

n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
410

_______421____7412

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
20

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
21
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
22
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
416
import numpy
202
import numpy
24
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
419
import numpy
26
import numpy
23
import numpy
22
import numpy
214

Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
21
Matrix =
 [[ 5 10]
 [15 20]]

The Transpose =
[[ 5 15]
 [10 20]]
22
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
426
import numpy
202
import numpy
24
n = 3
m = 3
val = [0] * n
for x in range [n]:
    val[x] = [0] * m
print[val]
419
import numpy
26
import numpy
23
import numpy
24
import numpy
214

đầu ra

import numpy
16

Xóa hàng và cột bằng Numpy

Ở đây, chúng tôi đang cố xóa các hàng bằng lệnh np. chức năng xóa []. Trong mã, đầu tiên chúng tôi cố gắng xóa hàng thứ 0, sau đó chúng tôi cố gắng xóa hàng thứ 2 và sau đó là hàng thứ 3

Bạn có thể tạo ma trận bằng Python không?

Tạo ma trận bằng Python . Python allows developers to implement matrices using the nested list.

Làm cách nào để giải một ma trận trong Python?

Để giải phương trình ma trận tuyến tính, hãy sử dụng hàm numpy. linalg. phương thức giải quyết[] trong Python . Phương pháp tính toán giải pháp "chính xác", x, được xác định rõ, i. e. , hạng đầy đủ, phương trình ma trận tuyến tính ax = b.

Chủ Đề