Aca*_*mia 2 python arrays numpy elements
我想得到c数组作为结果,但我不知道如何:
import numpy as np
a = xrange(10)
b = np.array([3,2,1,9])
Run Code Online (Sandbox Code Playgroud)
c由不在b中的元素组成:
c = np.array([0,4,5,6,7,8])
Run Code Online (Sandbox Code Playgroud)
也许更直接的解决方案如下:
import numpy as np
a = xrange(10)
b = np.array([3,2,1,9])
c = np.setdiff1d(a,b)
Run Code Online (Sandbox Code Playgroud)
结果如下:
In [7]: c
Out[7]: array([0, 4, 5, 6, 7, 8])
Run Code Online (Sandbox Code Playgroud)
您可以在文档中找到numpy数组的所有类似集合的操作:http: //docs.scipy.org/doc/numpy/reference/routines.set.html
| 归档时间: |
|
| 查看次数: |
2549 次 |
| 最近记录: |