KEMBAR78
1.a Numpy Code | PDF | Free Software | Computer Libraries
0% found this document useful (0 votes)
47 views2 pages

1.a Numpy Code

The document introduces NumPy, a Python library that provides efficient operations for manipulating large multi-dimensional arrays and matrices. It shows how NumPy can be used to create arrays from scratch or from existing Python lists, and demonstrates various array properties and operations like shape, size, indexing, slicing, and reshaping arrays into different dimensions.

Uploaded by

venkatesh m
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views2 pages

1.a Numpy Code

The document introduces NumPy, a Python library that provides efficient operations for manipulating large multi-dimensional arrays and matrices. It shows how NumPy can be used to create arrays from scratch or from existing Python lists, and demonstrates various array properties and operations like shape, size, indexing, slicing, and reshaping arrays into different dimensions.

Uploaded by

venkatesh m
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1/20/22, 9:58 PM 1.

a Numpy Code

In [3]:
## Numpy ( numerical for Python)

# It will provide more efficent storage and Data operation as size grows

#NumPy’s main object is the homogeneous multidimensional array.

import numpy as np

In [4]:
a = np.arange(15)

In [5]:
a

Out[5]: array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])

In [7]:
a.reshape(3,5)

Out[7]: array([[ 0, 1, 2, 3, 4],

[ 5, 6, 7, 8, 9],

[10, 11, 12, 13, 14]])

In [8]:
a.ndim

Out[8]: 1

In [9]:
a.dtype.name

Out[9]: 'int32'

In [10]:
a

Out[10]: array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])

In [11]:
a.size

Out[11]: 15

In [12]:
a[1:3]

Out[12]: array([1, 2])

In [13]:
a[4:]

Out[13]: array([ 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])

In [14]:
a[4]

Out[14]: 4

file:///C:/Users/rgandyala/Downloads/1.a Numpy Code.html 1/2


1/20/22, 9:58 PM 1.a Numpy Code

In [13]:
a[8]

Out[13]: 8

In [9]:
# Reverse the order of array

a[::-2]

Out[9]: array([14, 12, 10, 8, 6, 4, 2, 0])

In [12]:
x = a.reshape(3,5)

Out[12]: array([[ 0, 1, 2, 3, 4],

[ 5, 6, 7, 8, 9],

[10, 11, 12, 13, 14]])

In [14]:
x[2]

Out[14]: array([10, 11, 12, 13, 14])

In [19]:
# two rows and three columns

x[:2, :3]

Out[19]: array([[0, 1, 2],

[5, 6, 7]])

In [20]:
# three rows and two colums

x[:3, :2]

Out[20]: array([[ 0, 1],

[ 5, 6],

[10, 11]])

file:///C:/Users/rgandyala/Downloads/1.a Numpy Code.html 2/2

You might also like