Code Monkey home page Code Monkey logo

numpy-for-matrix-calculation's Introduction

Numpy for Matrix

Numpy là một thư viện dùng để xử lý dạng dữ liệu mảng trong Python tuy rằng trong Python cũng có "List" một dạng dữ liệu dùng để làm việc với mảng, tuy nhiên việc sử dụng Numpy cho phép xử lý dữ liệu nhanh hơn 50x.

Numpy là một trong những thư viện phổ biến trong Python dành cho việc tính toán ma trận, trong Numpy có một thư viện hay dùng để tính toán ma trận đó là numpy.linalg

Để cộng 2 ma trận

A = np.array([[2, 4], [5, -6]])
B = np.array([[9, -3], [3, 6]])
C = A + B  
print(C)

Để nhân 2 ma trận

A = np.array([[2, 4], [5, -6]])
B = np.array([[9, -3], [3, 6]])
C = np.dot(A,B)  
print(C) 

Với hàm dot() Nếu Vecto có dạng 1-D thì hàm sẽ trả về tích bên trong của các Vecto với Vecto có dạng 2-D thì hàm này tương tự như phép nhân Vecto thông thường, còn với dạng N-D thì nó là một tích tổng trên trục cuối cùng của a và trục cuối cùng thứ hai của b.

Với phép nhân Vecto nhiều chiều thì ta sử dụng toán tử "*"

C = A*B

Để chuyển vị 1 ma trận

A = np.array([[1, 1], [2, 1], [3, -3]])
print(A.transpose())

Để tính toán ma trận đảo ngược

a = np.array([[[1., 2.], [3., 4.]], [[1, 3], [3, 5]]])
ainv = np.inv(a)

Để tính toán hạng của ma trận

linalg.matrix_rank(A, tol=None, hermitian=False)

Trong đó A có thế mà mà trận hoặc là stack of matrix, hàm tính toán ma trận bằng cách sử dụng công thức SVD và trả về hạng của ma trận

Để tính định thức của ma trận

a = np.array([[[1., 2.], [3., 4.]], [[1, 3], [3, 5]]])
print(np.linalg.det(a))

numpy-for-matrix-calculation's People

Contributors

dhockingofthegods avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.