Python data Analysis NumPy (ii)

Source: Internet
Author: User

Numpy (numerical Python)
    • Foundation package for high performance scientific computing and data analysis;
    • Ndarray, multi-dimensional Array (matrix), with vector computing ability, fast, save space;
    • Matrix operations, without loops, can be done similar to MATLAB in the vector operation;
    • Linear algebra, random send generation;

Ndarray, n-dimensional array objects (matrices)
    • All elements must be of the same type
    • Ndim attribute, number of dimensions
    • Shape attribute, size of each dimension
    • Dtype property, data type

code example:

Import numpy# generate random multidimensional data for the specified dimension (two rows and three columns) data = Numpy.random.rand (2, 3) Print Dataprint type (data)
    • Execution Result:
[[0.49458614  0.14245674  0.26883084] [0.87402248  0.71089966  0.29023523]]<type ' Numpy.ndarray ' >

print ' Number of dimensions ', Data.ndimprint ' Dimensions: ', Data.shapeprint ' data type: ', Data.dtype
    • Execution Result:
Number of dimensions 2 dimension size:  (2L, 3L) data type:  float64

1. Create Ndarray

Nd.array (collection), collection is a Sequence object (list), nested sequence (list of lists)

# The list is converted to Ndarray (one-dimensional array) L = Range (Ten) data = Np.array (l) Print Dataprint Data.shapeprint Data.ndim
    • Execution results
[0 1 2 3 4 5 6 7 8 9] (10L, 1)

# The nested sequence is converted to NDARRAYL2 = [Range], range (Ten)]data = Np.array (L2) Print Dataprint Data.shape
    • Execution results
[[0 1 2 3 4 5 6 7 8 9] [0 1 2 3 4 5 6 7 8 9]] (2L, 10L)

Np.zeros,np.ones,np.empty full 0 or all 1 arrays of the specified size

    • The first parameter is Ganso, which is used to specify the size, such as (3,4)
    • Empty does not always return a total of 0, something returned is an uninitialized random value

Python data Analysis NumPy (ii)

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.