Please if you know than answer..pls don\'t give me any type of answer.. thanks..
ID: 3882871 • Letter: P
Question
Please if you know than answer..pls don't give me any type of answer.. thanks...this is python 221...Using 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 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: 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.Please if you know than answer..pls don't give me any type of answer.. thanks...this is python 221...Using 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 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: 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.
Please if you know than answer..pls don't give me any type of answer.. thanks...this is python 221...Using 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 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: 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.
Explanation / Answer
a)
ii)
Befor using numpy we have to import it and we can give the new short name for easy to use:
>>> import numpy as np
Using the command np.zeros((m, n), datatype) we can craate an array. the argument to zeros() is (3, 4) which gives the dimention of the array. the second argument int give data type. we can use int8 for 8 bit integer otherwise it take the size as size of instalation of your numpy i.e if your numpy is 32 bit it will take int32
>>>A1=np.zeros((3,4), int)
to display the array A1
>>>A1
iii)
for dimention of array A1. Here it show A1 is two dymentional
>>>A1.ndim
2
for shape use this comand. It show that A1 is 3x4
>>>A1.shape
(3, 4)
the A1.size will give number of element in A1
>>>A1.size
12
A1.dtype give datatype of A1
>>>A1.dtype
dtype('int32')
iiii)
This will add 5 to each element of A1
>>>A2=A1+5
>>>A2
v)
In numpy index start from '0'. So for second row index is 1 and for 3rd colum index is 2
>>>A2[1, 2]=1
vi)
>>>A2[2, 1]=1
vii)
>>>A2[0, 3]=1
viii)
>>>A2
ix)
np.flipr(A2) will filp the A2 horrozentally
>>>A3=np.fliplr(A2)
The np.flipud(A3) flip A3 verticaly and we get reverse in both dimention
>>>A3=np.flipud(A3)
>>>A3
b)
ii)
np.arange(1,10) give 10 values starting from 1 so we get [1,2,3,4,5,6,7,8,9]
>>> B1=np.arange(1,10)
>>>B1
iii)
B1[0:3] will give subaary of B1 from index 0 to index lessthen 3
>>>B2=B1[0:3]
>>>B3=B1[3:6]
>>>B4=B1[6:9]
>>>B2
>>>B3
>>>B4
iiii)
>>> B5 = 4*B4 + 3*B3 - 2*B2
>>>B5