Python Learning Notes (iii) __python

Source: Internet
Author: User

SCIPY Module

1, on File save and read operations, there are a variety of ways, such as

Use Io.savemat () and Io.loadmat () of Io in scipy;

For pictures you can use the Misc misc.imread () in scipy or Pyplot in Matplotlib ()

Among them, NumPy also provides the operation of text files: Numpy.loadtxt () and Numpy.savetxt ()

For reading text and CSV files, there are also Numpy.genfromtxt () and Numpy.recfromcsv ()

More efficient, numpy-specific binary form of numpy.save () and Numpy.load ()

More advanced image input and output methods have Skimage.io

2. Linear algebra Operation Scipy.linalg

For example, to find the value of the determinant, you can use Linalg.det (a), where a is a numpy-defined matrix;

For example, we can use LINALG.INV (arr) to find the inverse matrix of a square matrix, and if arr is singular, it will cause errors.

SVD has Uarr, spec, Vharr = LINALG.SVD (arr), where, Urarr, spec, Vharr can be combined to force the original matrix, specifically:

Sarr = Np.diag (spec)
>>> Svd_mat = Uarr. Dot (Sarr). Dot (Vharr) >>> NP. Allclose (Svd_mat, arr) True

3, interpolation operation: scipy.interpolate

For 1-dimensional interpolation functions, there are linear_interp = interp1d (measured_time, measures)

In which, you can set the parameter kind= ' cubic ' to change the interpolation type, the default is linear interpolation


4. Optimize and fit: scipy.optimize

Curve_fit (), Minimize (f, x0, method= "L-bfgs-b"), basinhopping to find the global best; parameters can be set in addition to method bounds, such as bounds= ((0,10),)

Minimize_scalar ()

If there are multiple arguments in the function, the variable can be written in the form of a vector;

Root finds a variable with a function of 0;


5, the geometric deformation of the image, from scipy import ndimage # Shift, Roate, zoom


6, Image expansion corrosion Operation Ndimage.binary_opening (IMG). Binary_closing (IMG)


7, the image of different areas of the block with different colors as a different label, you can use Ndimage.label (mask) method



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.