NumPy – A Replacement for MatLab
NumPy is often used along with packages like SciPy (Scientific Python) and Matplotlib (plotting library). This combination is widely used as a replacement for MatLab, a popular
platform for technical computing. However, Python alternative to MatLab is now seen as a more modern and complete programming language.
It is open-source, which is an added advantage of NumPy.
The most important object defined in NumPy is an N-dimensional array type called ndarray. It describes the collection of items of the same type. Items in the collection can be accessed using a zero-based index.
Every item in a ndarray takes the same size as the block in the memory. Each element in ndarray is an object of the data-type object (called dtype).
Any item extracted from ndarray object (by slicing) is represented by a Python object of one of array scalar types. The following diagram shows a relationship between ndarray, data-type object (dtype) and array scalar type −
An instance of ndarray class can be constructed by different array creation routines described later in the tutorial. The basic ndarray is created using an array function in NumPy as follows-
numpy.array
It creates a ndarray from any object exposing an array interface, or from any method that returns an array.
Example
Create a NumPy array:
import numpy as np
arr = np.array([1, 2, 3, 4, 5]) print(arr)
print(type(arr))
What is NumPy?
NumPy is a Python library used for working with arrays.
It also has functions for working in domain of linear algebra, fourier transform, and matrices.
NumPy was created in 2005 by Travis Oliphant. It is an open source project and you can use it freely.
NumPy stands for Numerical Python.
网友评论