Python data analysis Numpy (numerical python Basic)

Source: Internet
Author: User

# import NumPy module
1 ImportNumPy as NPTenA = Np.random.random ((2,4)) One a AOut[5]: -Array ([[[0.20974732, 0.73822026, 0.82760722, 0.050551 ], -[0.77337155, 0.06521922, 0.55524187, 0.59209907]])

# Calculate the And, Min, max values of all data in the matrix A Np.sum (a) atOUT[7]: 3.812057513268513 - Np.min (a) -OUT[8]: 0.05055099733013646 - Np.max (a) -OUT[9]: 0.8276072194278252 - Print("a=", a) ina= [[0.20974732 0.73822026 0.82760722 0.050551 ] -[0.77337155 0.06521922 0.55524187 0.59209907]]

# axis=0 for columns, Axis=1 for rows
 to Print("min", Np.min (a)) +Min 0.05055099733013646
#求每列当中的最小值 - Print("lmin:", Np.min (a,axis=0)) theLmin: [0.20974732 0.06521922 0.55524187 0.050551 ] * Print("lmin:", Np.min (A,axis=1)) $Lmin: [0.050551 0.06521922]Panax Notoginseng Print("sum:", Np.sum (A,axis=1)) -Sum: [1.8261258 1.98593171]

# reshape data, 3 rows, 4 columns theA = Np.arange (2,14). Reshape (3,4) + A AOut[16]: theArray ([[[2, 3, 4, 5], +[6, 7, 8, 9], -[10, 11, 12, 13]])

# Ndarray minimum, maximum number of values $ Print(Np.argmin (A)) $ 0 - Print(Np.argmax (A)) -11 the Print(Np.mean (A)) -7.5Wuyi Print(Np.average (A)) the7.5 - Print(A.mean ()) Wu7.5
# cumsum Iteration Add the A -Out[24]: inArray ([[[2, 3, 4, 5], the[6, 7, 8, 9], the[10, 11, 12, 13]])Bayi Print(A.cumsum ()) the[2 5 9 14 20 27 35 44 54 65 77 90] the A -Out[27]: -Array ([[[2, 3, 4, 5], the[6, 7, 8, 9], the[10, 11, 12, 13]])
# Clip (A, a_min, A_max) will determine the data in the Ndarray, the value of less than A_min is assigned to A_min, is greater than the A_max of the assignment A_max, the value between this is the same. the Print(Np.clip (a,5,8)) the[5 5 5 5] -[6 7 8 8] the[8 8 8 8]]
# Determine Ndarray order, vector of several dimensions
About A.ndim -OUT[30]: 2101 A102Out[31]: 103Array ([[[2, 3, 4, 5],104[6, 7, 8, 9], the[10, 11, 12, 13]])106 A.ndim107OUT[32]: 2108 a109Out[33]: theArray ([[[0.20974732, 0.73822026, 0.82760722, 0.050551 ],111[0.77337155, 0.06521922, 0.55524187, 0.59209907]]) the A.ndim113OUT[34]: 2 the A theOut[35]: theArray ([[[2, 3, 4, 5],117[6, 7, 8, 9],118[10, 11, 12, 13]])

Python data analysis Numpy (numerical python Basic)

Related Article

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.