Python data analysis and presentation [first week]

Source: Internet
Author: User
Tags integer numbers scalar

Question mark in the Ipython

Get the relevant descriptive information

%run System files

Execute a file

Ipython mode command

%magic Show all the Magic commands

%hist Command History input information

%PDB automatically enters the debugger after an exception occurs

%reset Delete all variables or names in the current namespace

%WHO displays Ipython variables already defined in the current namespace

%time statemnent gives code execution time

%timeit statement executes code multiple times, calculates average execution time

Basic methods of reading data

Dimensions: the organization of data

One-dimensional data list array

A set of data can have different data types in the structure list, with the same array type

Two-bit data combined form of multiple one-dimensional data

Extended formation of multidimensional data in sexual dimension

High-dimensional data dictionary

One data list (ordered) collection (unordered)

High-dimensional data dictionary form or data representation format (JSON XML YAML)

NumPy

Np.ndarray

Import NumPy as NP

Make one-dimensional vector image variable

One dimension data type is often the same to save memory and time

Ndarray

Actual data

Metadata that describes the data

The following table starts from 0

Dimensions of Axis axis data

Number of rank rank axes

Ndarray properties of an object

. Ndim number of rank axes or number of dimensions

Scale n row m column of the. Shape object

. Size object Element number

The element type of the. Dtype Object

. itemsize the size of each element in bytes

Element type of Ndarray

bool

INTC 32 or 64

int p The integer used for the index is consistent with sszie_t in C int32 or Int64

Int8 int16 int32 Int64

Uint8-16-32-64

float16-32-64/

Complex64 Real parts are 32-bit floating-point type

complex128 Real parts are 64-bit floating-point type

When each element row is different, the non-homogeneous object avoids using it as much as possible.

Methods for generating Ndarray

1 creating from List tuples

Np.array (, Dtype=np.float32) can specify type

2 using functions to create

Np.arange () elements from 0 to n-1

Np.ones (Shape) generates a full 1 type based on shape, which is a tuple type

Np.zeros (Shape) Ibid.

Np.full (shape,val) generates the Authority Val's

Np.eye (n) n-Order unit matrix

Np.ones_like (a) similar in shape

Np.zeros_like (a)

Np.zeros_like (A,val)

Np.linspace (1,10,4, endpoint=false) starting position the Germplasm element contains several elements

Np.logspace (1,2,base=4) 4^1-4^2 geometric series

Np.concatenate ((b)) Merge two Nparray

Methods of Ndarray

. Reshape (Shape) does not change the array element, returns an array of shape shapes, the original array does not change

. Resize (Shape) modifies the original array (the original array is changed) resize does not accept negative numbers ( -1) reshape can

. swapaxes (AX1,AX2) swap two dimensions of n dimension

. Flatten () to reduce the dimension of the array, return a one-dimensional arrays, the original array unchanged

Type transformation of Ndarray

New_a=a.astype (New_type)//Np.int specifically that type has PY self-determination

(Do not change the original data) create a new array, copy

Array goto List

. ToList ()

Much slower.

Array Manipulation index slices

A[1:4:2] Start number: termination Number: Step

Does not contain a final value

a[0,1,2] This is OK.

A[-1,-2,-3] This is a right-to-left index

A[:,1,-3]

A[:,1:3,:]

A[:,:,::2] The last dimension is step 2

Operation of Ndarray

Scalar operations

1 each element in the array is calculated with it

A=a/a.mean ()

Scalar elements

Np.abs (x)

Np.fabs ()

NP.SQRT ()

Np.squar ()

Np.log () np.log10 () np.log2 ()

Np.ceil () Np.floor ()

Np.rint () rounding

NP.MODF () returns the decimal and integer numbers of the array as two separate arrays

Np.cos cosh sin sinh tan tanh

Np.exp ()

Np.sign ()

+-*/**

Np.maximum (x, y) Np.fmax ()

Np.minimum (x, y) np.fmin () to find the corresponding maximum minimum value

Np.mod (x, y) elements and modulo operations

Np.copysign (x, y) copies the symbol of the Y element to the corresponding element in the corresponding array x

><==!= generating an array of type bool

Python data analysis and presentation [first week]

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.