Python Please
**Bold is code**
Recap of two-dimensional arrays and their numpy implementation
import numpy as np
my_2d_array = np.array([[1,2],[3,4],[5,6]])
print("This is my_2d_array:")
print(my_2d_array)
print("This array has shape " + str(my_2d_array.shape) + " as there are " + str(my_2d_array.shape[0]) + " rows and " + str(my_2d_array.shape[1]) + " columns.")
print("The entry of the array with row index " + str(1) + " and column index " + str(1) + " has value " + str(my_2d_array[1,1]))
1) In this problem, implement a TwoDArray class that is meant to mimic (some of) the functionality of a two-dimensional numpy array. DO NOT use numpy at any point.
1A) Give the class an __init__ method
Make sure that the variable array is a valid input. This means you should
a) Make sure that array is a list of lists. and
b) Make sure that each of the inner lists has the same length. You do not need to check for anything else.
Rise the appropriate error(s) if these conditions are not met. It is up for you to decide if you should raise a TypeError, KeyError, IndexError, ValueError, ZeroDivisionError, etc. When raising the error, you should also give an informative error message.Assume that all numbers are ints or float,s to only worry about checking that the variable array is a list of lists.
1A)
def __init__(self, array):
self.array = array
*** What would be the rest of the code?
Algorithm:
- Start
- Create a class called TwoDArray with array as its attribute
- Implement constructor to initialize the data
- Implement checkType() method which checks whether the array is list of lists of not. if not, then raise an error with specific message else return true
- Implement checkLength() method which checks whether all the lists inside the list have same length or not. if not, raise an error with appropriate error message else return true
- Implement __repr__() method, that checks the validity of data by calling checkType() and checkLength() methods. If the array is valid, it returns the array else returns "Invalid Input"
- Inside the main method, create an object of TwoDArray and print the obejct
- Stop
Step by stepSolved in 4 steps with 2 images
- Matrix Multiplication• Write a multiplication function that accepts two 2D numpy arrays,and returns the product of the two. This function should test that thearrays are compatible (recall that the number of columns in the firstmatrix must equal the number of rows in the second matrix). Thisfunction should test the array sizes before attempting themultiplication. If the arrays are not compatible, the function shouldreturn -1. solve in pythonarrow_forwardC#arrow_forward//Required Functionvoid func(int array_1[],int array_2[],int size){ for(int i=0;i<size;i++){ if(array_2[i]>array_1[i]){ array_1[i]=array_2[i]; } } return;} //main function to test the function.int main(){ int size=6; int a[]={1,5,9,8,7,6}; int b[]={1,4,10,12,7,15}; printf("First array before function call: "); for(int i=0;i<size;i++){ printf("%d ",a[i]); } func(a,b,size); //call to the created function printf("\nFirst array after function call: "); for(int i=0;i<size;i++){ printf("%d ",a[i]); } return 0;} 1. Write the statements to do the following: write a prototype for your function in the previous problem write a main function which includes the following steps declare two arrays of ints with 25 elements each prompt the user and read values into both arrays call your function from the previous problem print both arraysarrow_forward
- Prompt: In Python language, write a function that applies the logistic sigmoid function to all elements of a NumPy array. Code: import numpy as np import math import matplotlib.pyplot as plt import pandas as pd def sigmoid(inputArray): modifiedArray = np.zeros(len(inputArray)) #YOUR CODE HERE: return(modifiedArray) def test(): inputs = np.arange(-100, 100, 0.5) outputs = sigmoid(inputs) plt.figure(1) plt.plot(inputs) plt.title('Input') plt.xlabel('Index') plt.ylabel('Value') plt.show() plt.figure(2) plt.plot(outputs,'Black') plt.title('Output') plt.xlabel('Index') plt.ylabel('Value') plt.show() test()arrow_forwardWhat does each line of code mean?arrow_forwardC code that prints the elements of a 5 * 4 integer array whose elements are generated randomly.arrow_forward
- Return the First Element in an Array JavaScript Create a function that takes an array containing only numbers and return the first element. Examples getFirstValue ([1, 2, 3]) → 1 getFirstValue ([80, 5, 100])→ 80 getFirstValue ([-500, 0, 50])-500arrow_forwardJava - When using an array to do a binary search, what additional requirement is placed on the array?arrow_forwardA single dimensional array might be treated as a 2-dimensional array.arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY