jeudi 29 novembre 2018

How to add an array twice by two TRUE conditions?

this is my code:

import numpy as np
from scipy.ndimage.interpolation import shift

B = np.array([[0, 0, 0, 0, 0],
          [0, 0, 0, 0, 0],
          [0, 0, 0, 0, 0],
          [0, 0, 0, 0, 0],
          [0, 0, 0, 0, 0]])

F = np.array([[0, 0, 0, 0, 0],
          [0, 0, 0, 0, 1],
          [0, 0, 0, 0, 1],
          [0, 0, 0, 0, 0],
          [0, 0, 0, 0, 0]])

M = np.array([[1, 2, 1, 2, 1],
          [1, 2, 1, 2, 1],
          [1, 2, 1, 2, 0],
          [1, 2, 1, 2, 1],
          [1, 2, 1, 2, 1]])

if F[2, 4] == 1:
    B = np.add(F, M)

if F[1, 4] == 1:
    M_shift = shift(M, (-1, 0), cval=0)
    B = np.add(M_shift, F)

print(B)

I want to add M to B if the condition for F is true. In this example both if-conditions are true and i thought that my code will add two times M to B. But apparently it's not working? What is wrong?

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire