"Python data Analytics Combat" 3 NumPy Library

Source: Internet
Author: User

    • Initializing an array

arr = Np.array ([[1,2],[3,4]])

arr = Np.array ([[1,2],[3,4]], Dtype=complex)

arr = Np.zeros ((3,4))

arr = Np.ones (())

arr = Np.arange (4,10). Reshape (2,3)

arr = Np.linspace (0,1,6) #[0.0,0.2,0.4,0.6,0.8,1.0]

arr = Np.random.random (3)

arr = Np.random.random ((5,2))

    • Array built-in functions

Type (arr): Numpy.ndarray

Arr.dtype:int32, float64 ...

Arr.ndim:2

Arr.size:4

Arr.shape: (2l,2l)

Arr.itemsize:4

    • Array calculation function

Arr+1: Elements and

Arr*2: Elemental Product

ARR1+ARR2: Elements and

ARR1*ARR2: Elemental Product

Np.dot (arr1, ARR2): Matrix product

Sin (arr): element trigonometric Functions

sqrt (arr): Elemental root

Arr.sum (): All elements and

Arr.min (): Minimum value for all elements

Arr.max (): all element Maximum value

Arr.mean (): Average of all elements

    • Array iteration function

Np.apply_along_axis (Np.mean, Axis=0, Arr=arr): Iteration by column

Np.apply_along_axis (Lambda x:x*2, Axis=1, Arr=arr): Iteration by row

    • Boolean array:

arr<0.5

    • Stitching arrays:

Np.vstack ((arr1, ARR2)): Vertically into the stack

Np.hstack ((arr1, ARR2)): Horizontal into the stack

    • Cut fraction Group:

Np.vsplit (arr, n): Vertically split N part

Np.hsplit (arr, n): Horizontal split N part

Np.split (arr, [1,3,5], Axis=1): Vertical split

    • Array Save/Read

Np.save (' Data.npy ', arr)

arr = np.load (' data.npy ')

"Python data Analytics Combat" 3 NumPy 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.