3D Array: Use python to solve this problem. We already know how to operate 2D arrays. Now we have to use 3D arrays in order to construct LCS with 3 parameters. Multidimensional array means multiple arrays of different dimensions or sizes can be held by a single array. We will learn about 3D arrays with an example. Suppose we want to store midterm and final marks separately of four different courses of three students in a single array. We can easily do it by using a 3D array.   Python: for i in range(len(A)):     print("Student: ",(i+1))     for j in range(len(A[i])):         print("Course: ",(j+1))         print("Marks of Mid and Final: ")         for k in range(len(A[i][j])):             print(A[i][j][k],end=" ")         print()     print()   OUTPUT:  Student:  1 Course:  1 Marks of Mid and Final:  30 25 Course:  2 Marks of Mid and Final: 35 40 Course:  3 Marks of Mid and Final: 41 45 Course:  4 Marks of Mid and Final: 26 26   Student:  2 Course:  1 Marks of Mid and Final: 41 45 Course:  2 Marks of Mid and Final: 43 47 Course:  3 Marks of Mid and Final: 49 44 Course:  4 Marks of Mid and Final: 46 47   Student:  3 Course:  1 Marks of Mid and Final: 10 15 Course:  2 Marks of Mid and Final: 35 20 Course:  3 Marks of Mid and Final: 11 17 Course:  4 Marks of Mid and Final: 29 16

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter6: Arrays
Section: Chapter Questions
Problem 17RQ
icon
Related questions
Question

3D Array: Use python to solve this problem.

We already know how to operate 2D arrays. Now we have to use 3D arrays in order to construct LCS with 3 parameters. Multidimensional array means multiple arrays of different dimensions or sizes can be held by a single array. We will learn about 3D arrays with an example.

Suppose we want to store midterm and final marks separately of four different courses of three students in a single array. We can easily do it by using a 3D array.

 

Python:

for i in range(len(A)):

    print("Student: ",(i+1))

    for j in range(len(A[i])):

        print("Course: ",(j+1))

        print("Marks of Mid and Final: ")

        for k in range(len(A[i][j])):

            print(A[i][j][k],end=" ")

        print()

    print()

 

OUTPUT: 

Student:  1

Course:  1

Marks of Mid and Final: 

30 25

Course:  2

Marks of Mid and Final:

35 40

Course:  3

Marks of Mid and Final:

41 45

Course:  4

Marks of Mid and Final:

26 26

 

Student:  2

Course:  1

Marks of Mid and Final:

41 45

Course:  2

Marks of Mid and Final:

43 47

Course:  3

Marks of Mid and Final:

49 44

Course:  4

Marks of Mid and Final:

46 47

 

Student:  3

Course:  1

Marks of Mid and Final:

10 15

Course:  2

Marks of Mid and Final:

35 20

Course:  3

Marks of Mid and Final:

11 17

Course:  4

Marks of Mid and Final:

29 16





Students
2
A
2 3
Courses
OI 2 3
2
234
3,
EXAMS
Mid finnl
15
This is the pictorial view of the given scenario.Normally we can denote an array of 3
dimensions by this notation A[ ]I I ]. If we initialize this array empirically it will be like,
A[3][4][2]
Here, A is a 3D array where it has a size of 3 which represents 3 students. Each of 3
indices can hold an array of size 4 which indicates the different courses. And indices of
these arrays can hold arrays of size 2 where each index represents the marks of mid
and final.
For extracting the specific values from array A, we can simply use these instructions,
1. print(A[0][1][0])
2. print (A[2][2][1])
3. print(A[1][3][0])
First command will give 35 as output because first it will access the 0 th index of A.
Then it will go through the index number 1 of it's connected array and finally index
number 0 of the array which is connected with the index number 1 of 2nd array will be
accessed and give its value as output which is 35. Same procedure will be applied for
the rest of the instructions. The second and third commands will give outputs 17 and 46
respectively. For traversing this array you can use the given codes.
Transcribed Image Text:Students 2 A 2 3 Courses OI 2 3 2 234 3, EXAMS Mid finnl 15 This is the pictorial view of the given scenario.Normally we can denote an array of 3 dimensions by this notation A[ ]I I ]. If we initialize this array empirically it will be like, A[3][4][2] Here, A is a 3D array where it has a size of 3 which represents 3 students. Each of 3 indices can hold an array of size 4 which indicates the different courses. And indices of these arrays can hold arrays of size 2 where each index represents the marks of mid and final. For extracting the specific values from array A, we can simply use these instructions, 1. print(A[0][1][0]) 2. print (A[2][2][1]) 3. print(A[1][3][0]) First command will give 35 as output because first it will access the 0 th index of A. Then it will go through the index number 1 of it's connected array and finally index number 0 of the array which is connected with the index number 1 of 2nd array will be accessed and give its value as output which is 35. Same procedure will be applied for the rest of the instructions. The second and third commands will give outputs 17 and 46 respectively. For traversing this array you can use the given codes.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 5 images

Blurred answer
Knowledge Booster
Arrays
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning