Basic Python scientific computing package-Numpy, python-numpy
I. Numpy Concept
Numpy (short for Numerical Python) is the basic package for Python scientific computing. It provides the following functions:
In addition to providing fast array processing capabilities for Python, Numpy also plays a major role in data analysis, that is, it serves as a container for transferring data between algorithms. For numeric data, the Numpy array is much more efficient than the built-in Python Data Structure in data storage and processing. In addition, libraries written in low-level languages (such as C and Fortran) can directly operate the data in the Numpy array without any data replication.
Ii. Highlights of Numpy
Compared with the basic data types of Python, it has the following outstanding advantages:
NumPy provides two basic objects: ndarray (N-dimen1_array object) and ufunc (universal function object ). Ndarray is used to store multi-dimensional arrays of a single data type. ufunc is a function for processing arrays.
Iii. ndarray object
The core of Numpy is the ndarray object, which encapsulates an n-dimensional array of homogeneous data types. It differs from the python sequence in the following ways:
Ndarray has a fixed size when being created: different from the list in python, changing the ndarray size will create a new array and delete the elements in the original data ndarray with the same data type ndarray for advanced mathematical operations on a large amount of data: generally, it is more efficient and simpler than python built-in sequences. More and more python-based scientific and mathematical software use ndarray: it is not enough to know python's built-in sequence types, you also need to know how to use the ndaray Array
Ndarray Data Type
Numpy supports more numeric types than Python. For more information, see data types.
| Numpy Data Type |
Python type |
Description |
| Bool _ |
Bool |
Boolean (True or False), stored as a byte |
| Int _ |
Int |
Default Integer type (same as C long; usually int64 or int32) |
| Intc |
|
Same as C int (usually int32 or int64) |
| Intp |
|
Integer used for index (same as C ssize_t; usually int32 or int64) |
| Int8 |
|
Bytes (-128 to 127) |
| Int16 |
|
INTEGER (-32768 to 32767) |
| Int32 |
|
INTEGER (-2147483648 to 2147483647) |
| Int64 |
|
INTEGER (-9223372036854775808 to 9223372036854775807) |
| Uint8 |
|
Unsigned INTEGER (0 to 255) |
| Uint16 |
|
Unsigned INTEGER (0 to 65535) |
| Uint32 |
|
Unsigned INTEGER (0 to 4294967295) |
| Uint64 |
|
Unsigned INTEGER (0 to 18446744073709551615) |
| Float _ |
Float |
Float64. |
| Float16 |
|
Semi-precision floating point: Symbol bit, 5-digit index, 10-digit ending number |
| Float32 |
|
Single-precision floating point: Symbol bit, 8-digit index, 23-digit ending number |
| Float64 |
|
Double-precision floating point: Symbol bit, 11-bit index, 52-bit ending number |
| Complex _ |
Complex |
The abbreviation of complex128. |
| Complex64 |
|
The plural value, composed of two 32-bit floating points (real number and imaginary number) |
| Complex128 |
|
Plural, composed of two 64-bit floating points (real number and imaginary number) |
| 123456789101112 |
# Set the element type in the array as the type name. For backward compatibility, you can also usefloatOr string'float'x = np.array([1,2,3],dtype=np.float)print x # Viewing data typesprint x.dtype # Conversion function as a single value typeprint np.int32(1.3) # Convert the array type to generate a new copyprint x.astype(np.int) |
Result:
| 1234 |
[ 1. 2. 3.]float641[1 2 3] |
Thank you for reading the Shanghai shangxuetang article. For more information or support, please clickShanghai python Training