Question: I need help for advanced python program...Lab3 PartA Assignment Do these Steps: 1. Open a Command or Terminal Window and start the Jupyter server in
I need help for advanced python program...Lab3 PartA Assignment
Do these Steps:
1. Open a Command or Terminal Window and start the Jupyter server in the folder where you are storing your lab assignments and where the code exists that you will be loading into the notebook:
For Windows issue: start jupyter notebook or jupyter notebook.
1.
2. A command or terminal window will open, and a tab in your browser will open. Select a Python 3 Kernel to start (Menu: New -> Python 3).
3. Change the notebooks name to Lab3PartA-IntroNumPy: Use File menu, File->Rename
4. The first cell of the notebook must be a markdown cell of size 1. Type Lab3PartA: Intro to NumPy. Run the cell using the arrow button, icon on the toolbar.
5. Make the next cell a markdown cell of size 2. Type Author: First Last, where First is your first name and Last is your last name. Run the cell.
6. With the rest of this lab, you must create NumPy ndarrays and do specified operations with them. For each of the following steps create a markdown cell at the beginning of the step: calling them Step A, Step B, etc. Then beneath each markdown cell include all the cells necessary to do the subtasks listed. With these subtasks, you are required to use only NumPy operations. Do not use regular Python operations. You must not revert to standard Python data structures and operations - you must not use lists or loops. To start this group of tasks, add a cell and issue: import numpy as np
a) Step A (12 pts):
In this step, we are going to use array NumPy ufunc operators and array indexing to change array values. In addition, we are going to reverse the values in each row and then reverse the rows.
i. Create a markdown cell called Step A.
ii. Create an array with shape 3 by 4 of all zeros of type int. Use zeros. Call the array A1 and display it.
iii. Display the number of dimensions, the shape, the size and the data type of A1.
iiii. Create a new array called A2 that contains the elements of array A1 with 5 added to them. Display A2.
v. With A2, change the third element in the second row to 1.
vi. With A2, change the second element in the third row to 1.
vii. With A2, change the last element in the top row to 1.
viii. Display A2.
ix. Reverse the values in both dimensions of array A2, call the new array, A3, and display A3.
b) Step B (10 pts):
In this step, we are going to use array splitting and NumPy ufunc operators.
i. Create a markdown cell called Step B.
ii. Create an array with 9 elements containing the first nine counting numbers (1-9). Use arange. Call the array B1 and display B1.
iii. Split the array so that there are 3 elements in each subarray whose names are B2, B3, and B4. Display each of these subarrays.
iiii. Form a new array, called B5, by performing this array calculation: B5 = 4*B4 + 3*B3 - 2*B2. Display B5.
v. Find the max, min and sum of B5 and display them.
c) Step C (12 pts):
In this step, we are going to use summing of array rows and concatenation.
i. Create a markdown cell called Step C.
ii. Create a 10 element array with the first 10 positive odd integers. Call the array C1. Use arange. Display C1.
iii. Reshape the C1 array to a (5, 2) array and call it C2. Display C2.
iiii. Create a new (5, 1) array that is the sum of each row in C2. Call the new array C3. Display C3.
v. Concatenate C2 and C3, such that C2 occupies the first two columns and C3 the last column. Call the new array C4.
Display C4.
vi. Display the number of dimensions, the shape, the size and the data type of C4.
d) Step D (10 pts):
In this step, we are going to use broadcasting to center an array:
i. Create a markdown cell called Step D.
ii. Create array with shape 8 by 4 of uniformly distributed random values, called D. Use random.random. Display D.
iii. Compute the mean aggregate across the first dimension of D and store the resulting array in DM and display DM.
iiii. Center the D array by subtracting the mean (this is broadcasting) and call the resulting array, DC. Display DC.
v. Verify that the array DC is in fact centered, by displaying the mean aggregate across the first dimension of DC and store the resulting array in DA and display DA.
e) Step E (21 pts):
In this step, we are going to work with Boolean arrays, fancy indexing and sorting.
i. Create a markdown cell called Step E.
ii. Create a 2-D array with shape 3 by 5 containing random integers in the range 1-8 inclusive. Use random.randint. Call the array E, and display E.
iii. Find the median of the array E, called it med_E. Display med_E.
iiii. Use a comparison operator or ufunc to create a Boolean array called EML, containing True, False values for the array expression E < med_E. Display EML.
v. Display the count of True values in EML using a NumPy function.
vi. Use a comparison operator or ufunc to create a Boolean array called EMG, containing True, False values for the array expression E > med_E. Display EMG.
vii. Display the count of True values in EMG using a NumPy function.
viii. Create a Boolean array called EME, that can be used to determine the elements of E, that contain the median, med_E. Display EME.
ix. Display the count of elements of E, that contain the median, med_E.
x. Use a Boolean operator and a NumPy function, to display the count of indices in array E, that are between med_E - 2 and med_E + 2, inclusive.
xi. Create the array ES, from array E, that first reshapes the array to a 15 element array, and next sorts the elements in ascending order. Display the sorted ES array.
xii. Using fancy indexing, display the contents of the middle element of ES, index equal to 7, the element two less than the middle element of ES, and the element two more than the middle element of ES.
f) Step F (10 pts):
In this step, we are going to transpose an array, and work with expressing conditional logic as array operations.
i. Create a markdown cell called Step F.
ii. Create a 33 element array with the first 33 positive integers. Call the array F1. Use arange. Display F1.
iii. Reshape the F1 array to a (11, 3) array and called it F2. Display F2.
iiii. Transpose the F2 array and call it F3. Display F3.
v. Use the Boolean condition, F3 % 3 == 0, to create the array F4. Display F4.
vi. Create an array, call it F5, that is the same shape as array F3, but whose values are changed to either a 3 or a 0, in the following manner: For every element of array F3 whose value is not a multiple of three, that position in array F5 will contain a 0, and for every element of array F3 whose value is a multiple of three, that position in array F5 will contain a 3. Use the where function and the F4 array to create the F5 array.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
