Create Numpy Arrays

“How to create numpy arrays” : In this tutorial, we will learn array creation in numpy. As you know array is a variable, which can store multiple values at same time. Python doesn’t support arrays but python have lists which can be used same like arrays.

Numpy is python library, which used to working with arrays. We can create numpy arrays using array() function. The type of numpy array is <class ‘numpy.ndarray’> . Here ndarray is array object in numpy.

Check the example below to understand, how to create numpy array

Output/Results

Check Type

we can check type of array using type() built-in function.

Output/Results

Dimensions in Numpy Array

A array dimension is a specific direction of an array. Arrays inside the array is called multi-dimensional array.

Below you can see how we can create one, two and three dimensional arrays in Numpy.

One dimensional array in Numpy (1-D)

One dimension array is a uni-direction array. In numpy it represents a row of a column.

check the following example to understand one dimensional array

Output/Results

Two Dimensional Array(2-D)

A two dimensional array is the collection of one dimensional arrays. Check the example below

Output/Results

Three Dimensional Array (3-D)

A three dimensional array is the collection of two dimensional arrays. Check the following example

Output/Results

Check Shape of an array

Numpy provides a shape attribute to check the number of elements (i.e., the length) for each dimension (axis) of the array.

Output/Results

Check number of dimensions in an array

Numpy Provides ndim attribute to check the number of dimensions of an array

Output/Results

Check total number of elements in numpy array

Numpy Array offers a size attribute to check the number of elements in an array

Example

Output/Results

Get More Python Tutorials