Numpy matrix operation

Source: Internet
Author: User

Matrix assignment

>>> x1=np.arange(0,5)  # array([0, 1, 2, 3, 4])>>> x2=np.arange(1,6)  # array([1, 2, 3, 4, 5])>>> x3=np.linspace(0,5,6) # array([ 0.,  1.,  2.,  3.,  4.,  5.])


Matrix transpose

>>> Transpose (x2.reshape () # If the dimension is not changed, the returned value is still array ([1, 2, 3, 4, 5]) array ([1], [2], [3], [4], [5])


Matrix Multiplication

#[0, 1, 2, 3, 4] x [1, 2, 3, 4, 5]‘>>> dot(x1.reshape(1,5),transpose(x2.reshape(1,5)))array([[40]])


Matrix Inversion

>>> linalg.inv([[1,2],[3,4]])array([[-2. ,  1. ],       [ 1.5, -0.5]])


File Access

>>> A = NP. arange () >>>. shape = 3, 4> aarray ([0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11]) >>>. tofile (". bin ") >>> B = NP. fromfile (". bin ", dtype = NP. float) # Read data by float type> B # The data read is an incorrect array ([2.12199579e-314, 6.36598737e-314, 1.06099790e-313, 1.4854255e-313, 1.90979621e-313, 2.33419537e-313])>. dtype # view dtypedtype ('int32 ')> B = NP. fromfile (". bin ", dtype = NP. int32) # Read data according to the int32 type >>> B # The data is a one-dimensional array ([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])> B. shape = 3, 4 # modify the shape of B according to the shape of a> B # This time, array ([0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11])

Numpy matrix operation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.