Python (vii, numpy efficient data processing)

Source: Internet
Author: User

The main function of NumPy is to perform matrix operations

To import a package first when you use it

Import NumPy as NP

Np.version.version to view version information

# Building a one-dimensional array
N1=np.array ([one-off]) notice the parentheses outside.


N1.shape Output Dimension degrees

# Building a two-dimensional array
N2= Np.array ([[[1,2,3],[4,5,6]]) a generous bracket with two small square brackets inside
N2.shape

(2, 3)

Here are some of the more around people, read more and remember

# Build Ndarray quickly
# Sequence Creation:
Np. arange#类似于 a range in Python to create a first Ndarray object with a dimension of 15. 
OUT[154]:
Array ([0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14])
In [156]:
Np. Arange (2,3,#起点, end, step value. Contains the start value, without the end value. 
OUT[156]:
Array ([2.,  2.1,  2.2,  2.3,  2.4,  2.5,  2.6,  2.7,  2.8,  2.9])
In [159]:
Np. Linspace (1,#起点, end point, number of points in the interval. The beginning and end points are included. 
OUT[159]:
Array ([  1.,   2.,   3.,   4.,   5.,   6.,   7.,   8.,   9.,  10.])
In [160]:
Np. Arange (0,1,#0 to 1 Step 0.1 array, the array does not contain 1   
OUT[160]:
Array ([0.,  0.1,  0.2,  0.3,  0.4,  0.5,  0.6,  0.7,  0.8,  0.9])
In [163]:
Np. Linspace (# Start: 0, End 1, number of elements 5. 
OUT[163]:
Array ([0.  ,  0.25,  0.5,  0.75,  1.  ])

Np.eye (3) # diagonal matrix (three rows three columns)

Array ([[1.,  0.,  0.],       [0.,  1.,  0.],       [0.,  0.,  1.]]

Np.random.rand (3,2) #随机数矩阵: Three rows, two columns

Note the point:

a[:,:] # The first colon represents the cut out of all the rows, and the second colon represents the cut out of all the columns.

C1=np.arange (reshape) (2,5,5)
Np.save (' D:/c1 ', C1)
# well-preserved array, default suffix of NPY
# Multiple arrays are saved using the Savez method.

# in the case of the root path, write directly as above

 # but in other paths,np.save (' C:\\users\\asus\\desktop\\python course \\a1 ', A1)

A1=np.arange (reshape) (2,5,5) #????
Np.save (' C:\\users\\asus\\desktop\\python course \\a1 ', A1)
Np.load (' C:\\users\\asus\\desktop\\python course \\a1.npy ')


# Read
# Load method loading data in numpy format
# Savetxt,loadtxt method load data in text format similarly

NumPy y Function Reference
Build function action
Np.array (x) converts the input data into a Ndarray
Np.array (x, Dtype) converts the input data to a type of Ndarray
Np.asarray (array) converts the input data into a new (copy) Ndarray
Np.ones (n) generates an n-length one-dimensional all-one ndarray
Np.ones (n, dtype) generates an n-length type that is a one-dimensional all-one ndarray of Dtype
Np.ones_like (Ndarray) generates a single ndarray with the same shape as the parameter
Np.zeros (n) generates an n-length one-dimensional full 0 Ndarray
Np.zeros (n, dtype) generates a one-dimensional full 0 Ndarray of an n-length type bit dtype
Np.zeros_like (Ndarray) similar to Np.ones_like (Ndarray)
Np.em Pty (n) generates an uninitialized one-dimensional n-length Ndarray
Np.em Pty (n, Dtype) Q generates an N-length type that is dtype uninitialized one-dimensional ndarray
NP.EM Pty (Ndarray) similar to Np.ones_like (Ndarray)
Np.eye (n) creates an n-N unit matrix (diagonal is 1 and the remainder is 0)
Np.identity (N)
Np.arange (NUM) generates a one-dimensional ndarray from 0 to num-1 steps 1
。。。。。。

And so forth no longer attached

Stock-related statistics calculation
? The closing price and volume in the given IBM share price data read into
? Calculate volume weighted average price VWAP (close price)
? Calculate time Weighted average price TWAP (close price)
? Find out the extreme difference of the IBM stock closing price
? Calculates the median, mean, and variance of its close price
? Calculate the return rate of a stock (simple yield vs. logarithmic yield)
? What is the number of days to calculate the logarithmic yield yield greater than 1%?

Python (vii, numpy efficient data processing)

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.