Categories: NumpyPython

Introducing Numpy array in Python

We provide affordable online training course(via ZOOM meeting) for Python and R programming at fundamental level, click here for more details.

Numpy is a large module in Python programming. It handles mainly numeric data analysis, and is also the basis of another large module, Pandas in Python. The heart of Numpy is data object type ndarray. Numpy array stores same type of data in an array. An array usually has dimension (how many axes, or rank), its data type (integer, float, string, or more), and shape (size for each axis in its rank). Numpy array can be created using array() function. Next code example show how to create simple one-dimensional array with Numpy in Python from list as input.

#import Numpy module
import numpy as np
#create a one-dimensional array, from a list of 5 items
a1 = np.array([7, 210, 23,53,99])
#show the array
a1
#output
array([  7, 210,  23,  53,  99])
#type of array object
type(a1)
#output
numpy.ndarray
#type of data in the array
a1.dtype
#output
dtype('int32')
#dimension of array
a1.ndim
#output
1
#how many elements in total stored in the array
a1.size
#output
5
#size of each axis of the dimension
a1.shape
#output
(5,)

Numpy ndarray can be built with more than one dimension. The next example shows creation of a two-dimensional array,

#a two-dimensional array creation
a2 = np.array([[1, 3,5], [2, 4,6]])
#show the element type of array
a2.dtype
#output
dtype('int32')
#dimension of the array
a2.ndim
#output
2
#size, or total elements of the array
a2.size
6
#shape of the array
a2.shape
#output
(2, 3)

You can also watch videos on our YouTube channel for more understanding of Python programming skills.

wilsonzhang746

Recent Posts

Download R Course source files

Click here to download R Course source files !

2 months ago

Download Python Course source files

Click here to download Python Course Source Files !

2 months ago

How to create a data frame from nested dictionary with Pandas in Python

For online Python training registration, click here ! Pandas provides flexible ways of generating data…

5 months ago

How to delete columns of a data frame in Python

For online Python training registration, click here ! Data frame is the tabular data object…

5 months ago

Using isin() to check membership of a data frame in Python

Click her for course registration ! When a data frame in Python is created via…

5 months ago

How to assign values to Pandas data frame in Python

We provide affordable online training course(via ZOOM meeting) for Python and R programming at fundamental…

5 months ago