Numpy_operations (numberical operations on arrays)

Source: Internet
Author: User

First, elementwise operations

1, with scalars:

Input:

Import NumPy as np
a = Np.array ([1, 2, 3, 4])
A + 1
Output:

Array ([2, 3, 4, 5])

Input:

2**a
Output:

Array ([2,  4,  8, 16])

2. All arithmetic operates elementwise: input:

b = Np.ones (4) + A number creates an array with a value of 1 and then subtracts 1 (each element Plus)
b
a-b# the corresponding element
Output:

Array ([ -1.,  0.,  1.,  2.])
Input:

A * b
Output:

Array ([2.,  4.,  6.,  8.])
Input:

j = Np.arange (5)
2** (j + 1)-J
Output:

Array ([2,  3,  6, 13, 28])

3. Matrix multiplication:

Input:

c = NP. ((3,3))
C.dot (c) #矩阵乘法
Output:

Array ([[3.,  3.,  3.],
       [3.,  3.,  3.],
       [3.,  3.,  3.]]

4. Comparison and bitwise operation of matrices:

5, Transcendental function:

6, the shape does not match the operation


7, upper triangular matrix, transpose

Np.triu is the upper triangular matrix and the np.tril is the lower triangular matrix.


8, matrix comparison:


Second, the Sub module Numpy.linalg realize the basic linear algebra (Linear algebra), such as solving linear systems, singular value decomposition, and so on. However, it is not guaranteed to compile with valid routines, so we recommend using SCIPY.LINALG, detailed in the Scipy_linalg section
1, and Operations (total sum, by row/column sum)


2, mean value (mean), median (median), standard deviation (STD)


3, to find the maximum, minimum, maximum index, minimum index


4, the logical operation in the array


5, the overall comparison of the array


Np.zeros ((100,100))--a matrix that produces a 100*100 with a value of all 0

Np.all () all numbers are compared



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.