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
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.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fafc370c2-0278-4830-8365-c4b2fd589557%2F27002e63-2817-4bf8-9c3d-2c0868ebad1b%2F9qspj2s_processed.png&w=3840&q=75)

Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 5 images









