python中两个numpy数组之间的区别

时间:2022-05-08 12:55:43

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:

如何在Python中找到这两个数组之间的区别,给出:

[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!

对不起,如果这是一个业余问题 - 但任何帮助将不胜感激!

2 个解决方案

#1


25  

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

numpy非常简单,只需减去数组:

diffs = array1 - array2

I get:

我明白了:

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

#2


7  

you can also use numpy.subtract

你也可以使用numpy.subtract

example:

例:

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

print 'the difference =', np.subtract(array1, array2)

which gives you

给你的

the difference = array([0.1, 0.2, 0.3])

#1


25  

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

numpy非常简单,只需减去数组:

diffs = array1 - array2

I get:

我明白了:

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

#2


7  

you can also use numpy.subtract

你也可以使用numpy.subtract

example:

例:

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

print 'the difference =', np.subtract(array1, array2)

which gives you

给你的

the difference = array([0.1, 0.2, 0.3])