Question: In Python 3 Suppose you have a four-dimensional array A[, j, k, 1] with dimensions, 1-0, ,10 ], j= != [O, , 10], where 10

In Python 3

In Python 3 Suppose you have a four-dimensional array A[, j, k,

Suppose you have a four-dimensional array A[, j, k, 1] with dimensions, 1-0, ,10 ], j= != [O, , 10], where 10 , j0 , k0 , 10, are user defined parameters, write a program that splits the array in four blocks according to the index sets: Block 1: = [0, , 10 //2], j [0, , j0 //2], k [0, , koj, I = [0, , 10] Block 2: = [0, , 10 //2], j = [j 0 //2+1, , j 0 ], k = [0, , k 0 ], 1 = [0, , 10] Block 3: = [ 0//2 + 1, , 10], j = [0, , jo //2], k = [0, , k 0 ], 1 = [0, , 101 where A must be set such that: A[ , j, k, 1 ] =l in Block 1, A[,j,k,l] Block 4. -2 in Block 2, A[ , j, k, 1 ] -3 in Block 3, A[i,j,k,1] -4 in Your program must create an iterator to traverse each block, setting the values using a for loop. For instance, the code below builds an iterator to traverse all elements of an (3,3,3,3) array;: In [ import numpy as np from itertools import product M-np.zeros ( (3,3,3)) cids - product ( (0,1,2), (0,1,2),(0,1,2)) for i in cids: M[1] += 1 print(i) print(M) Create a function build_4Darray (i0,j0,ko,10) that receive the four dimensions and return the array with values set in the blocks as defined above. Run the tests below to ensure the array is built correctly: In [ ] Abuild _4Darray (2,4,3,3) assert AI0,1,1,0]- 1 assert AI0,3,1,012 assert A[2,1,1,0]-3 assert A[2,3,1,0]-4

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!