Question

In: Computer Science

Use NumPy to create a My_Array; a 3 by 3 array where in,m = n +...

  1. Use NumPy to create a My_Array; a 3 by 3 array where in,m = n + m. (e.g., the first row first column would be 0+0=0, second row first column would be 1+0=1, etc). complete the following using NumPy:
    1. Compute the mean, median, range, and variance of this array
    2. Find the inverse or pseudo inverse
    3. Find the determinant
  2. Perform the following operations on My_Array
    1. Create My_1D_Array by reshaping My_Array into a 1-dimensional array
    2. Create a new array that is the transpose of My_1D_Array
    3. Add this new array to My_1D_Array, what is the result? Why is this the result we see?

Solutions

Expert Solution

Adding the transpose and the original matrix will result in the original matrix*2.

All the functions are built into the numpy library.

CODE :

import numpy as np

My_arr = np.fromfunction(lambda m, n: m + n, (3, 3), dtype=int)

mean = np.mean(My_arr)
median = np.median(My_arr)
r = np.ptp(My_arr)
variance = np.var(My_arr)
print("Mean : ",mean," Median : ",median," Range : ",r," Variance : ",variance)

pinv = np.linalg.pinv(My_arr)
print("Pseudo-Inverse :\n ",pinv)

det = np.linalg.det(My_arr)
print("Determinant : ",det)

a1 = My_arr.flatten()
a2 = My_arr.transpose()
a3 = My_arr+a2

print("Flattened array : ",a1,"\nTranspose : \n",a2,"\n Transpose + My_arr :\n",a3)


Related Solutions

Develop a python program to - Create a 2D 10x10 numpy array and fill it with...
Develop a python program to - Create a 2D 10x10 numpy array and fill it with the random numbers between 1 and 9 (including 0 and 9). - Assume that you are located at (0,0) (upper-left corner) and want to move to (9,9) (lower-right corner) step by step. In each step, you can only move right or down in the array. - Develop a function to simulate random movement from (0,0) to (9,9) and return sum of all cell values...
1) Load the data from lab6_precipitation.csv into a numpy array; 2) Make a numpy array with...
1) Load the data from lab6_precipitation.csv into a numpy array; 2) Make a numpy array with the years 1916-2016 and dtype=int; 3) Make a numpy array with the months 1-12 and dtype=int; 4) Print out the shape of the data array and the lengths of the years and month array. If the length of your year array does not equal the number of rows in your data array, or the length of your months array does not equal the number...
Given the existence of two-dimensional array double A[M][N], where M and N are #defined as the...
Given the existence of two-dimensional array double A[M][N], where M and N are #defined as the number of rows and columns, respectively, define a function named sqabsmax that accepts array A as an argument (i.e. input parameter) and returns the square of the maximum absolute value element in A. Use the const qualifier if appropriate. Only show the function definition. Do not write an entire program with a main function. Just write the definition for function sqabsmax. in C
Create a function to output a one dimensional double array Mwith n elements where the...
Create a function to output a one dimensional double array M with n elements where the first three elements are 1 and each subsequent element is the sum of previous three elements before it. Name the function myArray. Write the function in the correct format to be used to create a Matlab function. Call the function in correct format to output the array with 7 elements.
Create a program that calculates the average of 3 test scores. Make use of an array...
Create a program that calculates the average of 3 test scores. Make use of an array to store the integer scores. const int size = 3; int testScores[size]; Send this array to a function that actually calculates and returns the average. 1. Tell the user what the program does. 2. Prompt the user to enter the integer scores. ( Use a for loop to do this. ) 3. Create and implement a function with prototype: double average( int a[], int...
In C create an array of 4 integers. Assign a pointer to the array. Use the...
In C create an array of 4 integers. Assign a pointer to the array. Use the pointer to find the average value of the elements in the array and display the results on the screen.
Write a C++ program that has a function which given n>=0, create an array length n*n...
Write a C++ program that has a function which given n>=0, create an array length n*n with the following pattern, shown here for n=3 : {0, 0, 1, 0, 2, 1, 3, 2, 1} (spaces added to show the 3 groups) generateGroups(3) → [0, 0, 1, 0, 2, 1, 3, 2, 1] generateGroups(2) → [0, 1, 2, 1] generateGroups(4) → [0, 0, 0, 1, 0, 0, 2, 1, 0, 3, 2, 1, 4, 3, 2, 1]
Create a C++ program that makes use of both concepts i.e. Array of structure and array...
Create a C++ program that makes use of both concepts i.e. Array of structure and array within the structure by using the following guidelines: 1. Create an Array of 5 Structures of Student Records 2. Each structure must contain: a. An array of Full Name of Student b. Registration Number in proper Format i.e 18-SE-24 c. An array of Marks of 3 subjects d. Display that information of all students in Ascending order using “Name” e. Search a particular student...
Using Python: Normalize a 5x5 random matrix hints: use numpy create a random matrix X apply...
Using Python: Normalize a 5x5 random matrix hints: use numpy create a random matrix X apply Normalization: (X - Mean) / Deviation
3) Create a Java program that uses NO methods, but use scanner: Write a program where...
3) Create a Java program that uses NO methods, but use scanner: Write a program where you will enter the flying distance from one continent to another, you will take the plane in one country, then you will enter miles per gallon and price of gallon and in the end it will calculate how much gas was spend for that distance in miles. Steps: 1) Prompt user to enter the name of country that you are 2) Declare variable to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT