0% found this document useful (0 votes)
8 views7 pages

Numpy 1 7

Uploaded by

waqarkhan03109
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)
8 views7 pages

Numpy 1 7

Uploaded by

waqarkhan03109
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/ 7

Python Packages

Numpy

Instructor:
Sayed Shahid Hussain
Research Associate,
AI in Healthcare, National Center of AI
UET Peshawar
Email: [email protected]
NumPy Introduction
NumPy
• 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, fourier transform, and
matrices.
• NumPy aims to provide an array object that is up to 50x faster than traditional Python
lists.
• NumPy was created in 2005 by Travis Oliphant. It is an open source project and you
can use it freely.
Installation of NumPy
• If you have Python and PIP already installed on a system, then installation of NumPy is
very easy.
• Install it using this command:
• C:\Users\Your Name>pip install numpy
Import NumPy:
• Once NumPy is installed, import it in your applications by adding the import keyword:
NumPy Creating Arrays
• NumPy is used to work with arrays. The array object in NumPy is called
ndarray.

• We can create a NumPy ndarray object by using the array() function.

• To create an ndarray, we can pass a list, tuple or any array-like object into
the array() method, and it will be converted into an ndarray
Dimensions in Arrays
• A dimension in arrays is one level of array depth
Access Array Elements & Slicing

• Access Array Elements


• You can access an array element by referring to its index number.
• The indexes in NumPy arrays start with 0, meaning that the first element has index 0, and the second has
index 1 etc.

• NumPy Array Slicing


• We pass slice instead of index like this: [start:end].
• We can also define the step, like this: [start:end:step].
NumPy Array Shape/reshape
• The shape of an array is the number of elements in each dimension.

• NumPy arrays have an attribute called shape that returns a tuple with each
index having the number of corresponding elements.

• By reshaping we can add or remove dimensions or change number of


elements in each dimension.
NumPy Array Iterating
• We can do this using basic for loop of python.

• The function nditer() is a helping function that can be used from very basic
to very advanced iterations.

You might also like