0% found this document useful (0 votes)
3 views32 pages

Numpy Basics for Data Mining in Python

ecam

Uploaded by

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

Numpy Basics for Data Mining in Python

ecam

Uploaded by

alaamabood97
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Data Mining: Python

LAB 03: Numpy


Outlines
 Python structure
 Numpy library
Ndarray
Buit-in functions
Operations
Indexing and Slicing
Arithmetic and Statistical Functions
Libraries
 NumPy
 Matplotlib
 Pandas
 Scikit-learn
 TensorFlow
 SciPy
 Keras
 …
Numpy
Numpy
Numpy is a Python library package for numerical computations.

Data structure in numpy is a multi-dimensional array object : ndarray.

Numpy includes a suite of functions for ndarray elements manipulation.


Numpy
One-dimensional : array ndarray

NumPy is the fundamental package for scientific computing in Python. It is a Python library that provides a
multidimensional array object, various derived objects (such as masked arrays and matrices), and an assortment
of routines for fast operations on arrays, including mathematical, logical, shape manipulation, sorting, selecting,
I/O, discrete Fourier transforms, basic linear algebra, basic statistical operations, random simulation and much
more.
One-dimensional : array ndarray
ndarray
Two-dimensional
array
Buit-in functions ndarray
ndarray

Buit-in
functions
ndarray

Buit-in
functions
Operatio
ns
Applying standard
operators such as
addition and
multiplication on
ndarray element.
Operatio
ns
Applying standard
operators such as
addition and
multiplication on
ndarray element.
Indexing and Slicing ndarray

Slicing arrays
Slicing in python means taking elements from one given
index to another given index.
We pass slice instead of index like this: [start:end].
We can also define the step, like this: [start:end:step].
• If we don't pass start its considered 0
• If we don't pass end its considered length of array in
that dimension
• If we don't pass step its considered 1
Indexing and Slicing ndarray

There are various ways to select a subset of


elements within a numpy array.

Assigning a numpy array (or a subset of its


elements) to another variable will pass a
reference to the array instead of copying its
values.
ndarray

Indexing
and
Slicing
Arithmetic and Statistical ndarray
Functions
Arithmetic and Statistical ndarray
Functions
Arithmetic and Statistical ndarray
Functions
Exercise 01 ndarray

Use Numpy to make element-wise comparison (<, ≤, >, ≥ ) of two proposed arrays.
Solution 01 ndarray

Use Numpy to make element-wise comparison (<, ≤, >, ≥ ) of two proposed arrays.
Exercise 02 ndarray

Create a 2d array matrix (5,5) with 1 on the border and 0 inside.

1 1 1 1 1
1 0 0 0 1
1 0 0 0 1
1 1 1 1 1
Solution 02 ndarray
Exercise 03 ndarray

Create a matrix (6,6) filled as follows:


Use the extended slice syntax ‘ [:: 3 ]’ that means start at element 0, step 3
Solution 03 ndarray
Exercise 04 ndarray

Insert the correct slicing syntax to print the following selection of the array:

From (including) the second item to (not including) the fifth item.
Answer 04 ndarray
Next LAB :
Pandas
[Link]
ndarray

Buit-in
functions

You might also like