Numpy is one of the most important and foundational libraries in Data Science.
The key 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 an ndarray takes the same size of block in the memory. Each element in ndarray is an object of 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
To use NumPy library we first need to import the library. To create a numpy array we can use the function 'array' from numpy package.
The example above created a single dimension array. We can create two dimension array as below.
NumPy's array function is very smart. We can tell it the number of dimensions we want and it will create it appropriately from the input data.
We can specify the data type of array elements.
NumPy supports a much greater variety of numerical types than Python does.
For example, one of the most common used data types is the int32 which is a 32-bit integer.
A full reference of NumPy can be found here: https://numpy.org/doc/stable/reference/index.html
That's all for this short post about the very basics of NumPy. Next times, we will examine more about key features of NumPy.
Happy Numpying!
コメント