Python Data Analysis Toolkit (1)--numpy (i)

Source: Internet
Author: User

In the undergraduate stage, our common scientific calculation tool is MATLAB. Here is a very useful and powerful scientific computing library--numpy for Python.

    • A powerful N-dimensional array object (a powerful N-dimensional array of objects)
    • Sophisticated (broadcasting) functions (Advanced (broadcast? function
    • Tools for integrating C + + and Fortran code (integrated c/C + + and FORTRAN tools)
    • Useful linear algebra, Fourier transform, and random number capabilities (useful linear algebra, Fourier transform, and random numbers ability)

The above is the official document introduction, the specific information can be referred to this site: http://www.numpy.org/

This package is still installed in Pip install NumPy. We cited some examples in Ipython to learn some of its common operations. Of course, before this, it is recommended to first understand the matrix and other related mathematical knowledge, as a review of the university's line of the high number of parts.

1 #Import NumPy2>>>ImportNumPy as NP3 #generates an array of the specified content4>>> a = Np.arange (a). Reshape (3, 5)5>>>a6Array ([[[0, 1, 2, 3, 4],7[5, 6, 7, 8, 9],8[10, 11, 12, 13, 14]])9>>> A.shape#array number of rowsTen(3, 5) One>>> A.ndim#Array Dimension A2 ->>> A.dtype.name#element type in array - 'Int64' the>>> a.itemsize#the byte size of each element in the array -8 ->>> a.size#total number of array elements -15 +>>> type (a)#properties of output a -<type'Numpy.ndarray'> + #generating an array directly from a given element A>>> B = Np.array ([6, 7, 8]) at>>>b -Array ([6, 7, 8]) ->>>type (b) -<type'Numpy.ndarray'>

NumPy can generate the specified array.

1 C:\Users\Administrator\Desktop2 Λipython3Python 3.6.4 (V3.6.4:d48eceb, Dec, 06:54:40) [MSC v.1900 64bit (AMD64)]4Type'Copyright','credits' or 'License'  forMore Information5IPython 6.2.1--an enhanced Interactive Python. Type'?'  forHelp .6 7In [1]:ImportNumPy as NP8 9In [2]: A=np.zeros ([3,4])#generate all 0 arraysTen  Onein [3]: a AOut[3]: - array ([[0., 0., 0., 0.], - [0., 0., 0., 0.], the [0., 0., 0., 0.]) -  -In [4]: B=np.ones ([3,4])#generate all 1 arrays -  +in [5]: b -Out[5]: +Array ([[1., 1., 1., 1.], A[1., 1., 1., 1.], at[1., 1., 1., 1.]]) -  -In [6]: C=np.random.rand (3,4)#generating a random array -  -in [7]: C -Out[7]: inArray ([[[0.36417168, 0.24336724, 0.78826727, 0.42894367], -[0.77198615, 0.95897315, 0.25628233, 0.53995372], to[0.02777746, 0.25093856, 0.14544893, 0.10475779]]) +  -In [8]: D=np.eye (3)#Generating a unit array the  *in [9]: D $Out[9]:Panax NotoginsengArray ([[1., 0., 0.], -[0., 1., 0.], the[0., 0., 1.]]) +  AIn [ten]: E=np.mat ([[1,2,3],[4,5,6],[7,8,9]]) #矩阵化 the  +in [11]: E -Out[11]: $Matrix ([[[1, 2, 3], $[4, 5, 6], -[7, 8, 9]]) -  theIn []: F=np.power (e,2)#calculates the power of n times - Wuyiin [13]: F theOut[13]: -Matrix ([[[1, 4, 9], Wu[16, 25, 36], -[Dtype=, Bayi]],int32) About  $In []: g=f.t#Seek transpose matrix -  -in [15]: G -Out[15]: AMatrix ([[[1, 16, 49], +[4, 25, 64], the[9, Dtype=, Bayi]],int32) -  $In [16]:

Here's a distinction between array () and mat (). Beginners are easy to confuse.

Np.array (a) is the array of the list, and its multiplication with another narray is not done by matrix multiplication, but by multiplying the corresponding elements. and the mat (), in the above example can be clearly seen, he generated the object is a matrix. The array is about to be matrix. Using the shape () method on a matrix returns the dimension of the matrix, and the array returns its rows and columns. Detailed information can be found in the official documentation.

Python Data Analysis Toolkit (1)--numpy (i)

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.