Difference between two numpy arrays in python

user3263816 picture user3263816 · Feb 2, 2014 · Viewed 135.5k times · Source

I have two arrays, for example:

array1=numpy.array([1.1, 2.2, 3.3])
array2=numpy.array([1, 2, 3])

How can I find the difference between these two arrays in Python, to give:

[0.1, 0.2, 0.3]

As an array as well?

Sorry if this is an amateur question - but any help would be greatly appreciated!

Answer

jonrsharpe picture jonrsharpe · Feb 2, 2014

This is pretty simple with numpy, just subtract the arrays:

diffs = array1 - array2

I get:

diffs == array([ 0.1,  0.2,  0.3])