Python machine learning numpy function library

Source: Internet
Author: User

The NumPy library is a standalone module of the Python development environment, and most Python distributions do not have the NumPy library installed by default, so you must install the NumPy library separately after you install Python.

Enter the following command in the Python Shell development environment:


If no error is indicated, the NumPy function library is installed correctly.

The preceding command introduces all modules in the NumPy library to the current namespace.

Then enter the following command in the Python Shell development environment:

>>> Random.rand (bis)

Array ([[0.14934315,  0.1449608,  0.10937618,  0.11962542],
[0.04143021, 0.16427192, 0.42890596, 0.2950785],
[0.63548394, 0.89104911, 0.19498788, 0.35677273],
[0.3508607, 0.52253214, 0.75657235, 0.43606179]])

The above command constructs a random array of 4*4.

Call the mat () function to convert the array into a matrix and enter the following command:

>>> Randmat = Mat (Random.rand (bis))

Because a matrix is generated using random functions, the values that are output on different computers may be slightly different:

>>> randmat.i

Matrix ([[[4.56615396, -5.06383533, -0.95580269,  1.77517599],
[3.52460325, -1.68264237, -3.10410481, 0.68144572],
[4.49946852, 0.68792194,-2.99607457,-3.35777914],
[ -5.49861973, 3.25167152, 3.96853985, 0.35681462]])

. The I operator implements the inverse matrix operation and executes the following command to store the inverse matrix:

Invrandmat = randmat.i

The matrix multiplication is then performed to obtain the result of multiplying the matrix with its inverse matrix:

>>> Randmat*invrandmat

Matrix ([[  1.00000000e+00,  -4.44089210e-16,  -4.44089210e-16,
-3.33066907E-16],
[ -8.88178420e-16, 1.00000000e+00, 0.00000000e+00,
5.55111512E-17],
[ 4.44089210e-16, 0.00000000e+00, 1.00000000e+00,
-5.55111512E-17],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
1.00000000E+00])

The result should be the unit matrix, except that the other elements of the diagonal element 1,4*4 matrix should be all 0. The actual output results are slightly different, and many very small elements are left in the matrix, which results from the computer processing error. Enter the following command to get the error value:

>>> MyEye = Randmat*invrandmat
>>> Myeye-eye (4)

Matrix ([[  0.00000000e+00,  -4.44089210e-16,  -4.44089210e-16,
-3.33066907E-16],
[ -8.88178420e-16, 2.22044605e-16, 0.00000000e+00,
5.55111512E-17],
[ 4.44089210e-16, 0.00000000e+00, 0.00000000e+00,
-5.55111512E-17],
[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
0.00000000E+00])

The function eye (4) creates the unit matrix of the 4*4.

As long as you can successfully complete the above example, it means that the NumPy function library has been installed correctly and can be used to construct machine learning applications later.

Python machine learning numpy function library

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.