Using Python for data analysis (4) NumPy basics: ndarray simple introduction, numpyndarray

Source: Internet
Author: User

Using Python for data analysis (4) NumPy basics: ndarray simple introduction, numpyndarray

I. What is NumPy? NumPy is the basic package of Python scientific computing. It is designed for strict digital processing. I have provided more detailed introductions in my previous articles. I will not go into details here. Using Python for data analysis (1) Brief Introduction
2. What is ndarray? ndarray is a multi-dimensional array object. It has vector arithmetic and complex broadcast capabilities, and features fast execution speed and space saving.
An attribute of ndarray is homogeneous: All elements must be of the same type.
3. Create ndarray
Array () functionThe simplest method is to use the array () function provided by NumPy to directly convert the Python array to an ndarray. array () accepts all sequence objects, for example, convert a list to an ndarray: note that the returned value of this function is not necessarily 0, and may be other uninitialized junk values.
Arange () functionThis function is a number group version of the Python built-in function range. Usage: 4. ndarray Data Type
You can specify the data type of an element when creating an ndarray array. For example, the supported data types include integers, floating-point numbers, plural numbers, Boolean values, strings, and common Python objects ). When creating an ndarray array, if the specified type is not displayed, it will try to deduce a suitable data type.
Type conversion
Use the astype () method of ndarray to perform forced type conversion. When a floating point is converted to an integer, the fractional part is discarded. astype creates a new array, even if it is specified as the same type.
V. simple use of ndarray
Using ndarray allows us to perform operations on the elements in the list without loop. The syntax is the same as that for scalar elements. For example: use Python for data analysis (5) NumPy basics: ndarray indexes. If you are interested, please follow this blog and add comments for discussion.

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.