Python Please Recap of two-dimensional arrays and their numpy implementation  ** uploaded image ^ 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. If these conditions are not met you should raise the appropriate error(s). 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. With actual numpy arrays, all numbers are required to be the same datatype. You don't have to worry about that here. You can also assume that all numbers are ints or floats so you only have to worry about checking that the variable array is a list of lists.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Python Please

Recap of two-dimensional arrays and their numpy implementation 

** uploaded image ^

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.

If these conditions are not met you should raise the appropriate error(s). 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.

With actual numpy arrays, all numbers are required to be the same datatype. You don't have to worry about that here. You can also assume that all numbers are ints or floats so you only have to 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?

2 import numpy as np
3
4 my_2d_array
np.array([[1,2],[3,4],[5,6]])
5 print("This is my_2d_array:")
6 print(my_2d_array)
7 print("This array has shape
str(my_2d_array.shape[0]) +
+ str(my_2d_array.shape) +
as there are
%3D
rows and"
+ str(my_2d_array.shape[1]) +
columns.")
+ str(1) +
8 print("The entry of the array with row index "
" has value "
and column index
+ str(1) +
+ str(my_2d_array[1,1]))
Transcribed Image Text:2 import numpy as np 3 4 my_2d_array np.array([[1,2],[3,4],[5,6]]) 5 print("This is my_2d_array:") 6 print(my_2d_array) 7 print("This array has shape str(my_2d_array.shape[0]) + + str(my_2d_array.shape) + as there are %3D rows and" + str(my_2d_array.shape[1]) + columns.") + str(1) + 8 print("The entry of the array with row index " " has value " and column index + str(1) + + str(my_2d_array[1,1]))
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education