Best way to insert 3D array values ​​inside another larger array

There must be some kind of "pufonic" way to do this, but I don’t think that np.place, np.insertor np.putis what I am looking for. I want to replace the values ​​inside a large 3D array Awith the values ​​of a smaller 3D array B, starting at the location [i,j,k]in the larger array. See Figure:

I want to print something like A [i +, j +, k +] = B or np.embed (B, A, (i, j, k)), but of course this is not true.

EDIT: Oh, that is so. So I have to change the question to ask if this is the best way (where “best” means the fastest for an array of pots at 500x500x50 on a laptop):

s0, s1, s2 = B.shape
A[i:i+s0, j:j+s1, k:k+s2] = B

one 3D array inside another

+4
1

3D-.

"", , , :

def embed( small_array, big_array, big_index):
    """Overwrites values in big_array starting at big_index with those in small_array"""
    slices = [np.s_[i:i+j] for i,j in zip(big_index, small_array.shape)]
    big_array[slices]=small_array

, , , "" , big_array , small_array. , , - 1:1 small_array big_array ( length-1 small_array, ndim big_array), , - , small_array big_array "" small_array. , , , , .

+2

Source: https://habr.com/ru/post/1610674/


All Articles