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

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
In C++, create a 3-by-3 array that is capable of storing integers and initialize each entry...
In C++, create a 3-by-3 array that is capable of storing integers and initialize each entry to 0. Ask the user to supply a row and a column and a value, then put the value into the array at that row and column. Print the array to the screen as a table with 3 rows and 3 columns, and ask the user for another row, column, and value. Repeat until user inputs values for all entries. Once finished, compute and...
in phyton programming: with numpy Create a function called biochild.  The function has as parameters...
in phyton programming: with numpy Create a function called biochild.  The function has as parameters the number m and the lists ??????h?? and ??????h??.  The lists ??????h?? and ??????h?? contain 0’s and 1’s.  For example: ??????h?? = [1,0,0,1,0,1] and ??????h?? = [1,1,1,0,0,1]  Both lists have the same length ?.  The 0's and 1's represent bits of information (remember that a bit is 0 or 1).  The function has to generate a new list (child)....
( C language only )Generate a function  called randomnum(n,m,neg); where n and m are the lower and...
( C language only )Generate a function  called randomnum(n,m,neg); where n and m are the lower and upper bounds for the random number; the generated number is negative if a variable named neg is true .These numbers should be non-zero with a maximum absolute value of 15 . You must use bitwise arithmetic to calculate the modulus of the random numbers
2. Consider an n-cube, where n = 3. Is it possible to draw this on a...
2. Consider an n-cube, where n = 3. Is it possible to draw this on a two dimensional plane where the lines do not cross? If it is possible, draw it. If not, prove that it isn't possible.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT