Updated On : Jun-23,2020 Tags numpy, basics
Learning Numpy - Simple Tutorial For Beginners - NumPy - Ndarray Object Part 2

Learning Numpy - Simple Tutorial For Beginners - NumPy - Ndarray Object Part 2

What Is Ndarray Object?

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 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 −

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 −


It creates an ndarray from any object exposing array interface, or from any method that returns an

array.numpy.array(object, dtype = None, copy = True, order = None, subok = False, ndmin = 0)
Sr.No. Parameter & Description
1 object: Any object exposing the array interface method returns an array, or any (nested) sequence.
2 dtype: Desired data type of array, optional
3 copy: Optional. By default (true), the object is copied
4 order: C (row major) or F (column major) or A (any) (default)
5 subok: By default, returned array forced to be a base class array. If true, sub-classes passed through
6 ndmin: Specifies minimum dimensions of resultant array

Example 1

In [5]:
import numpy as np
a = np.array([1,2,3])
print (a)
[1 2 3]

Example 2

In [6]:
# more than one dimensions 
import numpy as np
a = np.array([[1, 2], [3, 4]])
print (a)
[[1 2]
 [3 4]]

Example 3

In [7]:
# minimum dimensions 
import numpy as np
a = np.array([1, 2, 3,4,5], ndmin = 2)
print (a)
[[1 2 3 4 5]]

The ndarray object consists of contiguous one-dimensional segment of computer memory, combined with an indexing scheme that maps each item to a location in the memory block.

Dolly Solanki  Dolly Solanki

  Support Us

Thank You for visiting our website. If you like our work, please support us so that we can keep on creating new tutorials/blogs on interesting topics (like AI, ML, Data Science, Python, Digital Marketing, SEO, etc.) that can help people learn new things faster. You can support us by clicking on the Coffee button at the bottom right corner. We would appreciate even if you can give a thumbs-up to our article in the comments section below.

 Want to Share Your Views? Have Any Suggestions?

If you want to

  • provide some suggestions on topic
  • share your views
  • include some details in tutorial
  • suggest some new topics on which we should create tutorials/blogs
Please feel free to let us know in the comments section below (Guest Comments are allowed). We appreciate and value your feedbacks.