"Machine Learning in Python" (NumPy)

Source: Internet
Author: User

#single-line comment" " Multi-line Comment Multiline Comment multi-line Comment" "#A.ndim The number of dimensions of the output array;#a.shape output Array form (several rows, several columns)#copy () copies an array#multiply each element in the a*2 array by 2#[1,2]*2 Array will become 4#a**2 a squared#[1,2]**2 unsuported operand type#array Access. Build outliers. Handles a value that does not exist. #clip () Trim off part of an interval boundary#mean () mean value#handling values that do not existImportNumPy as NPA= Np.array ([0,1,2,3,4,5]) b= A.reshape ((3,2))#Transport a array to B. Change B same to a.C= A.reshape ((3,2)). Copy ()#Change c No change a.they is depended.A[a>4] = 2#Trimming Outlier ValuesD= A.clip (0,2)#maximum of 2 in De= Np.array ([1,2,NP. nan,3,4])## Np.isnan (e) to determine if an array has an unreasonable valueF = E[~np.isnan (e)]## E[~np.isnan (e)] output a reasonable numberm= Np.mean (E[~np.isnan (e)])##均值. ##应该时常考虑如何将数组元素的循环处理冲Python中移到高度优化的NumPy: scipy extension function (validation negation)#example the sum of all squares of 1~1000Importtimeitnormal_py_sec= Timeit.timeit ('sum (x*x for x in Xrange ())', number= 1000) Naive_np_sec= Timeit.timeit ('sum (na*na)', Setup="Import NumPy as Np;na=np.arange (+)", number= 1000) Good_np_sec= Timeit.timeit ('Na.dot (NA)', Setup="import NumPy as NP; Na=np.arange (+)", number= 1000)Print("Normal Python:%f sec"%normal_py_sec)Print("Naive Python:%f sec"%naive_np_sec)Print("Good NumPy:%f sec"%good_np_sec)" "Normal python:0.081011 secnaive python:0.384903 secgood numpy:0.013812 sec Experience, there is no much difference. With" "

"Machine Learning in Python" (NumPy)

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.