0% found this document useful (0 votes)
14 views3 pages

Tp2 Fondamental Data Science

Uploaded by

atouiyakoub4
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)
14 views3 pages

Tp2 Fondamental Data Science

Uploaded by

atouiyakoub4
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/ 3

PW2 ESTIN 2024-2025

Exercise 1:
 Set up tools (Python, Anaconda…etc.) or use online notebooks.
Exercise 2: getting started with Numpy.
 Run at least 2 tasks from each category of the next:
Array Creation and Manipulation:
 Create a 1D array with values ranging from 0 to 9.
 Create a 2D array with shape (3, 4) filled with zeros.
 Create an array with 10 equally spaced values between 0 and 1.
 Create a random 3x3 matrix with values between 0 and 1.
 Create an array with all even integers between 10 and 50.
 Create a 5x5 identity matrix.
 Create an array with 20 logarithmically spaced values between 1 and 100.
 Reshape a 1D array into a 2D array of shape (2, 5).
 Transpose a 2D array.
 Extract all odd numbers from an array using boolean indexing.
Array Operations:
 Add two matrices element-wise.
 Multiply two matrices using matrix multiplication.
 Calculate the mean, median, and standard deviation of an array.
 Find the sum of each column in a 2D array.
 Calculate the dot product of two 1D arrays.
 Normalize the values in an array between 0 and 1.
 Find the index of the maximum value in an array.
 Replace all negative values in an array with zeros.
 Calculate the element-wise product of two arrays.
 Calculate the element-wise square root of an array.
Indexing and Slicing:
 Slice a 2D array to extract the second column.
 Get the diagonal elements of a 2D array.
 Select rows from a 2D array where the sum of elements is greater than a threshold.
 Reverse the rows of a 2D array.
 Get the elements at odd indices of a 1D array.
Random Number Generation:
 Generate an array of 10 random integers between 1 and 100.
PW2 ESTIN 2024-2025

 Create a random 5x5 matrix with values from a normal distribution.


 Shuffle the elements of an array randomly.
 Generate an array of random integers following a Poisson distribution.
 Generate an array of random floats between 0 and 1 with a specified shape.
Boolean Indexing and Filtering:
 Create a new array containing only the positive values of an existing array.
 Find the elements in an array that are divisible by 3.
 Create a mask for elements greater than a specific value in an array.
 Replace all elements greater than 10 in an array with 10.
 Count the number of elements greater than 5 in a 2D array.
Statistical Operations:
 Calculate the correlation coefficient between two arrays.
 Find the index of the first occurrence of a specific value in an array.
 Calculate the cumulative sum of a 1D array.
 Calculate the 75th percentile of an array.
 Calculate the mean along a specific axis of a 2D array.
Broadcasting and Vectorization:
 Multiply each element in an array by a scalar.
 Add a 1D array to each row of a 2D array using broadcasting.
 Multiply corresponding elements of two arrays with different shapes using broadcasting.
 Calculate the outer product of two arrays.
 Apply a custom function element-wise to an array.
File I/O:
 Save a NumPy array to a text file.
 Load a NumPy array from a text file.
 Save a NumPy array to a binary file.
 Load a NumPy array from a binary file.
 Save multiple arrays to a single compressed NPZ file.

Exercise 3:
 V= [0.5, 0.8, 0.9]
 M = [1.0, 0.3, 0.65; 0.5, 0.8, 0.9; 1.0, 0.3, 0.65]
Using NumPy:
PW2 ESTIN 2024-2025

Create the vector V.


 Create the matrix M, M transpose, Matrix G = MT*M.
 Extract vector 1, row 1, sub matrix (0-2,0-2), then the max, min, sum, and average of
each.
 Extract from M: (a) diagonal matrix. (b) identity matrix, (c) values bigger than 0.5.
 Insert a new row to M, and then insert a new column to M using random values.
 Calculate Euclidean distance of each two vectors of M using G.
 Verify if V is in M.
 Create a random sample of data (X values, and Y values) as to have 10 values of X in the
range [0; 11], and Y has a linear form Y= aX + b (a in [1.5; 1.8], and b in [4; 4.5] (Check
Linspace).
 Check if matrix N is a sub matrix of M.
 Create matrix of size (5,5) containing: (a) ones, (b) zeros, and (c) random values.
Exercise 4
Calculate Maclaurin series with NumPy

You might also like