擅长:python、mysql、java
<p>你可以使用两种不同的方法:有列表理解和没有列表理解。<em>使用</em>是“python方式”,但这取决于您的决定:</p>
<pre><code>from numpy import *
C = {0: [matrix([[ 8.87155979, 2.50616085]]), matrix([[ 0.46289077, 8.05592104]])],
1: [matrix([[-1.3115368 , 7.60922069]])],
2: [matrix([[ 0.46289077, 8.05592104]]), matrix([[-1.3115368 , 7.60922069]]), matrix([[ 3.4826805 , -0.73544937]])]}
y = [[ 8.87155979, 2.50616085]]
# without list comprehension
for x in C.values():
for m in x:
if all(m==y):
print(True)
# with list comprehension
print(any([all(m==y) for x in C.values() for m in x]))
</code></pre>