Python numpy Library Learning common functions (matrix operations) __ function

Source: Internet
Author: User
Tags square root
Matrix summation, maximum, minimum, average, log, open root, Square, decimal up
Import NumPy as np
a = Np.arange (10,100,5) print (
a)
print (' Vector size: ', a.size)
A36 = A.reshape (3,6)
Print (A36) print ('
-------------------')
print (' Sum: ', A36.sum ())
print (' Sum by line: ', A36.sum (Axis=1))
Print (' Sum by column: ', A36.sum (axis=0)) print ('
max: ', A36.max ()) Print (
' maximum per row: ', A36.max (Axis=1))
print (' Maximum per column: ', A36.max (axis=0)) print (' min
: ', A36.min ()) Print (
' Minimum per line: ', A36.min (Axis=1))
print (' Minimum value per column: ' , A36.min (axis=0)) print ('
average: ', A36.mean ()) print ('
average per line: ', A36.mean (Axis=1))
print (' Average per column: ', A36.mean (axis=0)) print ('
max index: ', A36.argmax ()) Print
(' Maximum index per row: ', A36.argmax (Axis=1))
print (' Maximum index per column: ', A36.argmax (axis=0)) print (
' log value: ', Np.log (A36)) print ('
log10 value: ', Np.log10 (A36)) print ('
Log2 value: ', Np.log2 (A36)) print ('
exponential value: ', Np.exp (A36)) print ('
square root: ', np.sqrt (A36)) Print
('------------- -------')
a = Np.random.random ((3,4)) *10 print (
a)
print (' Decimal rounding: ', Np.floor (a))
print (' Decimal rounding up : ', Np.ceil (a))
Matrix Subtraction
Import NumPy as np
A12 = Np.arange ()
print (A12)
A34 = A12.reshape (3,4)
print (A34)
# # structure can be directly used + * -/symbol for Operation
Print (A34 + A34)
print (A34 * A34)
A43 = A12.reshape (4,3)
print (A43)
# # The structure is not the same as dot () C10/>print (' Dot (): ', Np.dot (A43,a34))
matrix Stitching and splitting
Import NumPy as np
R23 = Np.random.random ((2,3))
R22 = Np.random.random ((2,2))
print (R23)
print ( R22)
# # Number of lines to stitch two matrices must be the same
print (' concatenation: \ n ', Np.hstack (R23,R22))
# # Concatenation of two matrices by column must be the same
r53 = Np.vstack ((R23,np.random.random (4,3))) Print
(' concatenation by column: \ n ', r53)

print (' Average of 3 pieces by column: \ n ', Np.hsplit (r53,3))
print (' Specify column index split, index 1 and index 2 each cut: \ n ', Np.hsplit (r53, (1,2))
print (' average of 3 in rows: \ n ', Np.vsplit (r53,3))
Print (' Specify row index split, index 1 and index 3 each cut: \ n ', Np.vsplit (r53, (1,3))

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.