0

Hi I am writing some long code so I will post a snippet of it here. Basically I have made an iterative code that builds a matrix of zeros, and a number that appears somewhere within those zeros to act as a radar. I only wanted the radar to update when there had been a change, so I set Radar1 equal to the old value of the radar, then put this function in

if Radar1.all() == Radar.all():
                print('yes')
                print(Radar)
                print(Radar1)
            else:
                print('no')

Here is the output As can be seen in the picture, the response is yes, both matrices are the same, then both matrices are printed, and one of them (Radar) is all zeros, whereas the other one (Radar1) has a 3 in the 3rd row down and 3rd column across. My point is they are two different matrices, and they are not the same, so why doesn't my code print no? Maybe I am missing something, thanks for the help in advance

Edit: I have tried to run a similar loop in a standalone code to make it easier to edit, and it works, but still can't get it to work in my main code. I am very confused: Standalone code Perhaps its because im using global variables in the main code? Any help would be appreciated

Maxwh
  • 11
  • 3
  • 1
    Welcome to Stack Overflow. In your own words, where the code says `Radar1.all() == Radar.all()`, what do you expect that to mean? How do you expect it to be executed, step by step? – Karl Knechtel May 25 '22 at 17:03
  • read the documentation of the `.all()` method. If it is numpy, then [it's here](https://numpy.org/doc/stable/reference/generated/numpy.all.html). It is not intended for this purpose. – trincot May 25 '22 at 17:04
  • [Please do not upload images of code/data/errors when asking a question.](//meta.stackoverflow.com/q/285551) Please read [ask] and [mre]. As for the new code, it does not work; it will *always* give a `'no'` result, because of a typo (look carefully at what is on the left and right hand sides of the `==`). – Karl Knechtel May 25 '22 at 17:05
  • `Radar.all()` and `Radar1.all()` are both `False` because both of those arrays contain zeros. Accordingly, `Radar1.all() == Radar.all()` is equivalent to `False == False`, which is, well, `True`. – jjramsey May 25 '22 at 17:10

0 Answers0