0

I am trying to manipulate a numpy array that contains data stored in an other array. So far, when I change a value in my array, both of the arrays get values changed:

 import numpy as np
 from astropy.io import fits

 image = fits.getdata("randomImage.fits")
 fft = np.fft.fft2(image)
 fftMod = np.copy(fft)
 fftMod = fftMod*2
 if fftMod.all()== fft.all():
    print "shit same same same "

 -- > shit same same same

Why is?

1 Answer 1

3

You misunderstood the usage of the .all() method. It yields True if all elements of an array are not 0. This seems to be the case in both your arrays or in neither of them.

Since one is the double of the other, they definetly give the same result to the .all() method (both True or both False)

edit as requested in the comments: To compare the content of the both arrays use element wise comparison first and check that all elements are True with .all:

(fftMod == fft).all()

Or maybe better for floats including a certain tolerance:

np.allclose(fftMod, fft)
Sign up to request clarification or add additional context in comments.

3 Comments

so just drop the .all() off fftMod and fft and you're set.
not quite, you have to change the parenthesis: (fftMod == fft).all()
@dnalow That is an essential point that should be included in your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.