NumPy Quick tutorial - Letsprogram

Share:
NumPy’s main object is the homogeneous multidimensional array. It is a table of elements (usually numbers), all of the same type, indexed by a tuple of non-negative integers. In NumPy, dimensions are called axes.

For example, you can create an array from a regular Python list or tuple using the array function. The type of the resulting array is deduced from the type of the elements in the sequences.

>>>import numpy as np
>>> a = np.array([1,2,3,4])
>>>a
array([1,2,3,4])
>>>a.dtype
dtype('int64')
>>>b = np.array([1.2,2.4,3.6,7.8])
>>>b
array([1.2,2.4,3.6,7.8])
>>>b.dtype
dtype("float64")

You can change the datatype of b array as int while declaring the b array. 

You can know the dimension of the array by using the shape attribute and also you can change the dimension by using the reshape method in NumPy.

When you want an array with all zeroes or all ones then you can use the method zeroes and ones.

>>> a = np.zeroes(4,dtype=float)
>>> b = np.ones(5,dtype=int)
>>>b
array([1,1,1,1,1])
>>>a
array([0.,0.,0.,0.])


Creating an array, shaping, and reshaping the array and operations on the array like transpose of the array, concatenate and array mathematics.

You can see a few examples in  the file: NumPy Quick tutorial

No comments

F