Question: 9.8 CHALLENGE: Working with arrays In addition to array creation and slicing, the video lectures introduced you to important ways to use numpy arrays: using

 9.8 CHALLENGE: Working with arrays In addition to array creation and

9.8 CHALLENGE: Working with arrays In addition to array creation and slicing, the video lectures introduced you to important ways to use numpy arrays: using array methods array arithmetic ufuncs (universal functions) Array arithmetic and ufuncs act on arrays in an element-wise fashion. They also make use of broadcasting to work with arrays of different sizes or arrays and scalars (a scalar is a simple number). Array methods Given the array a = np.array([[1, 2, 3], [10, 20, 30], [100, 200, 300]]), Compute and print 1. the "sums by rows", i.e., the sums go over the columns (should give [6, 60, 600]) (Hint: Use a. sum(axis ...) where you have to choose the correct axis to sum over.) 2. the "sums by columns", i.e., the sums go over the rows (the sum in the first column is 111) 3. the maximum of the array 4. the maxima of all rows 5. the mean of the sub-array formed by omitting the first row and column 6. the products by columns (.e., products over rows) but only including the first two columns (Hint: look for an appropriate ndarray method for the product.) See Basic reductions in the SciPy lecture notes for help and orientation. Array arithmetic Given the array b = np.arange(-6, 4) compute and print 1. The array formed by b? 1, where the b; are the elements of the array b. 2. The array formed by multiplying b with the scalar 100 3. The array formed by 2.0bi in reverse order. (Note: the base 2.0 must be a floating point number, for integer values a ValueError: Integers to negative integer powers are not allowed. is raised.) 9.8 CHALLENGE: Working with arrays In addition to array creation and slicing, the video lectures introduced you to important ways to use numpy arrays: using array methods array arithmetic ufuncs (universal functions) Array arithmetic and ufuncs act on arrays in an element-wise fashion. They also make use of broadcasting to work with arrays of different sizes or arrays and scalars (a scalar is a simple number). Array methods Given the array a = np.array([[1, 2, 3], [10, 20, 30], [100, 200, 300]]), Compute and print 1. the "sums by rows", i.e., the sums go over the columns (should give [6, 60, 600]) (Hint: Use a. sum(axis ...) where you have to choose the correct axis to sum over.) 2. the "sums by columns", i.e., the sums go over the rows (the sum in the first column is 111) 3. the maximum of the array 4. the maxima of all rows 5. the mean of the sub-array formed by omitting the first row and column 6. the products by columns (.e., products over rows) but only including the first two columns (Hint: look for an appropriate ndarray method for the product.) See Basic reductions in the SciPy lecture notes for help and orientation. Array arithmetic Given the array b = np.arange(-6, 4) compute and print 1. The array formed by b? 1, where the b; are the elements of the array b. 2. The array formed by multiplying b with the scalar 100 3. The array formed by 2.0bi in reverse order. (Note: the base 2.0 must be a floating point number, for integer values a ValueError: Integers to negative integer powers are not allowed. is raised.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!