Ma trận không là gì ngoài sự sắp xếp dữ liệu hoặc số theo hình chữ nhật. Nói cách khác, nó là một mảng dữ liệu hoặc số hình chữ nhật. Các mục theo chiều ngang trong ma trận được gọi là 'hàng' trong khi các mục theo chiều dọc được gọi là 'cột'. Nếu một ma trận có r số hàng và c số cột thì thứ tự của ma trận là r x c. Mỗi phần tử trong ma trận có thể là giá trị nguyên, giá trị động hoặc thậm chí có thể là số phức
ví dụ
// 3 x 4 matrix 1 2 3 4 M = 4 5 6 7 6 7 8 9 // 2 x 3 matrix in Python A = [ [ 2, 5, 7 ], [ 4, 7, 9 ] ] // 3 x 4 matrix in Python where entries are floating numbers B = [ [ 1.0, 3.5, 5.4, 7.9 ], [ 9.0, 2.5, 4.2, 3.6 ], [ 1.5, 3.2, 1.6, 6.5 ] ]
Trong Python, chúng ta có thể lấy ma trận đầu vào của người dùng theo nhiều cách khác nhau. Một số phương thức cho ma trận đầu vào của người dùng trong Python được hiển thị bên dưới
Mã số 1
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 63
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 64
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 65
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 66
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 67
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 68
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 69
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 68
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 61
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 62
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 63_______36
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 67____38
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 69
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 68
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 69
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 62
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 64
Enter the number of rows:2 Enter the number of columns:2 Enter the entries in a single line separated by space: 1 2 3 1 [[1 2] [3 1]]2
Enter the number of rows:2 Enter the number of columns:2 Enter the entries in a single line separated by space: 1 2 3 1 [[1 2] [3 1]]3
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 66
Enter the number of rows:2 Enter the number of columns:2 Enter the entries in a single line separated by space: 1 2 3 1 [[1 2] [3 1]]5
Enter the number of rows:2 Enter the number of columns:2 Enter the entries in a single line separated by space: 1 2 3 1 [[1 2] [3 1]]6______38
Enter the number of rows:2 Enter the number of columns:2 Enter the entries in a single line separated by space: 1 2 3 1 [[1 2] [3 1]]8
Enter the number of rows:2 Enter the number of columns:2 Enter the entries in a single line separated by space: 1 2 3 1 [[1 2] [3 1]]9
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 64
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 631
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 632
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 633
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 634
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 635
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 636
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 637
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 638
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 639____36
Enter the number of rows:2 Enter the number of columns:2 Enter the entries in a single line separated by space: 1 2 3 1 [[1 2] [3 1]]5
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 638
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 632
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 644
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 634
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 635
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 647
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 648
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 649
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 650
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 67
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 68
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 69
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 654
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 638
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 656
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 64
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 658
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 632
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 633
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 634
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 635
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 663
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 638
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 632
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 644
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 634
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 635
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 669
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 670
Enter the number of rows:2 Enter the number of columns:2 Enter the entries in a single line separated by space: 1 2 3 1 [[1 2] [3 1]]6______372
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 66
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 674
Enter the number of rows:2 Enter the number of columns:2 Enter the entries in a single line separated by space: 1 2 3 1 [[1 2] [3 1]]9
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 638
Enter the number of rows:2 Enter the number of columns:2 Enter the entries in a single line separated by space: 1 2 3 1 [[1 2] [3 1]]6
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 678
đầu ra
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 6
Lót
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 679
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 680
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 66
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 682
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 67
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 68
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 69
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 686
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 632
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 688
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 634
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 635
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 691
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 632
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 693
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 634
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 635
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 696
Mã số 2. Sử dụng chức năng
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 697 và
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 698.
Trong Python tồn tại một thư viện phổ biến tên là NumPy. Thư viện này là một thư viện cơ bản cho bất kỳ tính toán khoa học nào. Nó cũng được sử dụng cho mảng nhiều chiều và như chúng ta đã biết ma trận là mảng chữ nhật, chúng ta sẽ sử dụng thư viện này cho ma trận đầu vào của người dùng
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 699
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 600
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 64
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 65
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 66
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 67
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 68
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 69
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 68
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 61
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 62
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 63_______36
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 67____38
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 69
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 68
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 69
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 62
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 64
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 64
Enter the number of rows:2 Enter the number of columns:2 Enter the entries in a single line separated by space: 1 2 3 1 [[1 2] [3 1]]6______38
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 622
Enter the number of rows:2 Enter the number of columns:2 Enter the entries in a single line separated by space: 1 2 3 1 [[1 2] [3 1]]9
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 64
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 625
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 626
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 627
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 66
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 629
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 68
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 631
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 68
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 67
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 634
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 69
Enter the number of rows:2 Enter the number of columns:3 Enter the entries rowwise: 1 2 3 4 5 6 1 2 3 4 5 636