<jupyter_start><jupyter_text>insert_shape  Inserts sub-image into a larger image at the specified location.  Import packages<jupyter_code>import matplotlib.pyplot as plt
import numpy as np
import porespy as ps

ps.visualization.set_mpl_style()
np.random.seed(10)<jupyter_output><empty_output><jupyter_text>Create image and element:<jupyter_code>image = np.random.randint(1, 3, size=(5, 5, 5))
element = np.random.randint(10, 11, size=(3, 3, 3))
print(image)
print(element)<jupyter_output>[[[2 2 1 2 1]
  [2 2 1 2 2]
  [1 2 2 1 1]
  [2 1 1 1 1]
  [1 2 1 1 2]]

 [[2 1 1 2 1]
  [1 2 1 1 1]
  [2 2 1 2 2]
  [2 2 2 1 2]
  [1 1 1 1 2]]

 [[1 2 2 2 1]
  [2 1 2 2 1]
  [2 1 1 2 1]
  [1 1 2 2 1]
  [1 1 2 1 2]]

 [[2 1 2 2 1]
  [2 1 1 1 1]
  [1 2 1 2 1]
  [1 1 1 1 1]
  [1 2 2 1 2]]

 [[2 1 1 2 1]
  [1 2 1 1 1]
  [1 1 1 2 2]
  [2 1 1 1 2]
  [2 2 2 1 2]]]
[[[10 10 10]
  [10 10 10]
  [10 10 10]]

 [[10 10 10]
  [10 10 10]
  [10 10 10]]

 [[10 10 10]
  [10 10 10]
  [10 10 10]]]<jupyter_text>The image array and shape array are both arrays of the same dimensions, in this case 3-dimensional arrays.  Apply generator function:With different parameters  Corner<jupyter_code>im = ps.generators.insert_shape(im=image,
                                element=element,
                                center=None,
                                corner=[0, 0, 0],
                                value=1,
                                mode="overwrite")
print(im)<jupyter_output>[[[10 10 10  2  1]
  [10 10 10  2  2]
  [10 10 10  1  1]
  [ 2  1  1  1  1]
  [ 1  2  1  1  2]]

 [[10 10 10  2  1]
  [10 10 10  1  1]
  [10 10 10  2  2]
  [ 2  2  2  1  2]
  [ 1  1  1  1  2]]

 [[10 10 10  2  1]
  [10 10 10  2  1]
  [10 10 10  2  1]
  [ 1  1  2  2  1]
  [ 1  1  2  1  2]]

 [[ 2  1  2  2  1]
  [ 2  1  1  1  1]
  [ 1  2  1  2  1]
  [ 1  1  1  1  1]
  [ 1  2  2  1  2]]

 [[ 2  1  1  2  1]
  [ 1  2  1  1  1]
  [ 1  1  1  2  2]
  [ 2  1  1  1  2]
  [ 2  2  2  1  2]]]<jupyter_text>The element is anchored in the [0, 0, 0] corner.  Center<jupyter_code>im = ps.generators.insert_shape(im=image,
                                element=element,
                                center=[2, 3, 2],
                                corner=None,
                                value=1,
                                mode="overwrite")
print(im)<jupyter_output>[[[ 2  2  1  2  1]
  [ 2  2  1  2  2]
  [ 1  2  2  1  1]
  [ 2  1  1  1  1]
  [ 1  2  1  1  2]]

 [[ 2  1  1  2  1]
  [ 1  2  1  1  1]
  [ 2 10 10 10  2]
  [ 2 10 10 10  2]
  [ 1 10 10 10  2]]

 [[ 1  2  2  2  1]
  [ 2  1  2  2  1]
  [ 2 10 10 10  1]
  [ 1 10 10 10  1]
  [ 1 10 10 10  2]]

 [[ 2  1  2  2  1]
  [ 2  1  1  1  1]
  [ 1 10 10 10  1]
  [ 1 10 10 10  1]
  [ 1 10 10 10  2]]

 [[ 2  1  1  2  1]
  [ 1  2  1  1  1]
  [ 1  1  1  2  2]
  [ 2  1  1  1  2]
  [ 2  2  2  1  2]]]<jupyter_text>The image is centered at [2, 3, 2].  Value<jupyter_code>im = ps.generators.insert_shape(im=image,
                                element=element,
                                center=[2, 2, 2],
                                corner=None,
                                value=5,
                                mode="overwrite")
print(im)<jupyter_output>[[[ 2  2  1  2  1]
  [ 2  2  1  2  2]
  [ 1  2  2  1  1]
  [ 2  1  1  1  1]
  [ 1  2  1  1  2]]

 [[ 2  1  1  2  1]
  [ 1 50 50 50  1]
  [ 2 50 50 50  2]
  [ 2 50 50 50  2]
  [ 1  1  1  1  2]]

 [[ 1  2  2  2  1]
  [ 2 50 50 50  1]
  [ 2 50 50 50  1]
  [ 1 50 50 50  1]
  [ 1  1  2  1  2]]

 [[ 2  1  2  2  1]
  [ 2 50 50 50  1]
  [ 1 50 50 50  1]
  [ 1 50 50 50  1]
  [ 1  2  2  1  2]]

 [[ 2  1  1  2  1]
  [ 1  2  1  1  1]
  [ 1  1  1  2  2]
  [ 2  1  1  1  2]
  [ 2  2  2  1  2]]]<jupyter_text>The element was multiplied by value (5), before being inserted to the image.  Mode<jupyter_code>im = ps.generators.insert_shape(im=image,
                                element=element,
                                center=[2, 2, 2],
                                corner=None,
                                value=1,
                                mode="overwrite")
print(im)<jupyter_output>[[[ 2  2  1  2  1]
  [ 2  2  1  2  2]
  [ 1  2  2  1  1]
  [ 2  1  1  1  1]
  [ 1  2  1  1  2]]

 [[ 2  1  1  2  1]
  [ 1 10 10 10  1]
  [ 2 10 10 10  2]
  [ 2 10 10 10  2]
  [ 1  1  1  1  2]]

 [[ 1  2  2  2  1]
  [ 2 10 10 10  1]
  [ 2 10 10 10  1]
  [ 1 10 10 10  1]
  [ 1  1  2  1  2]]

 [[ 2  1  2  2  1]
  [ 2 10 10 10  1]
  [ 1 10 10 10  1]
  [ 1 10 10 10  1]
  [ 1  2  2  1  2]]

 [[ 2  1  1  2  1]
  [ 1  2  1  1  1]
  [ 1  1  1  2  2]
  [ 2  1  1  1  2]
  [ 2  2  2  1  2]]]<jupyter_text>The element has been inserted to the image. Since the mode was "overwrite" the specified section of the image is replaced by the element.<jupyter_code>im = ps.generators.insert_shape(im=image,
                                element=element,
                                center=[2, 2, 2],
                                corner=None,
                                value=1,
                                mode="overlay")
print(im)<jupyter_output>[[[ 2  2  1  2  1]
  [ 2  2  1  2  2]
  [ 1  2  2  1  1]
  [ 2  1  1  1  1]
  [ 1  2  1  1  2]]

 [[ 2  1  1  2  1]
  [ 1 12 11 11  1]
  [ 2 12 11 12  2]
  [ 2 12 12 11  2]
  [ 1  1  1  1  2]]

 [[ 1  2  2  2  1]
  [ 2 11 12 12  1]
  [ 2 11 11 12  1]
  [ 1 11 12 12  1]
  [ 1  1  2  1  2]]

 [[ 2  1  2  2  1]
  [ 2 11 11 11  1]
  [ 1 12 11 12  1]
  [ 1 11 11 11  1]
  [ 1  2  2  1  2]]

 [[ 2  1  1  2  1]
  [ 1  2  1  1  1]
  [ 1  1  1  2  2]
  [ 2  1  1  1  2]
  [ 2  2  2  1  2]]]
{'fraction_non_alphanumeric': 0.11338525629414961, 'fraction_numerical': 0.17768520195616735, 'mean_word_length': 1.1469673405909797, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '422275', 'license': 'MIT', 'n_tokens_mistral': 3068, 'n_tokens_neox': 2460, 'n_words': 939, 'path': 'examples/generators/howtos/insert_shape.ipynb', 'repo_name': 'jamesobutler/porespy', 'size': '5521'}