Ch-1 Numpy: Ndarray Ndarray
Ch-1 Numpy: Ndarray Ndarray
Ch-1 Numpy: Ndarray Ndarray
NumPy was created in 2005 by Travis Oliphant. NumPy stands for Numerical Python. NumPy is a
python library used for working with arrays. It also has functions for working in domain of linear
algebra and matrices. It is an open source project. The array object in NumPy is called ndarray, it
provides a lot of supporting functions that make working with ndarray very easy.
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.
NumPy arrays are stored at one continuous place in memory. NumPy is a Python library and is written
partially in Python, but most of the parts that require fast computation are written in C or C++. The
basic ndarray is created using an array function in NumPy.
Example 1
import numpy as np
a=np.array([1,2,3])
print a
output
[1, 2, 3]
Example 2
# Two dimensions
import numpy as np
print a
output
[[1, 2]
[3, 4]]
Assignment:
Q2. Create an ndarry with value ranging from 10 to 99 each spaced with a
difference of 5.
arr=np.arange(9).reshape(3,3)
print arr
arr=np.add(75,-98)
print arr