jeudi 14 mai 2020

Generating random unique 3D binary matrices

I created a list containing a thousand random 10*10*10 binary matrices.

P=[]
for idx in range (0,1000):
    s=(10,10,10)
    a=np.zeros(s)
    for i in range (0,10):
        for j in range (0,10):
            for k in range (0,10):
                c=np.random.random(1)
                if c>0.5:
                    c=1
                else:
                    c=0
                a[i][j][k]=c
    P.append(a)

After that, I tried the following to make sure none of the matricies are repeated. However, I get an error for that.

unique_set=[]
for idx in P:
    if idx not in unique_set:
        unique_set.append(idx)
unique_set

This is the error I get:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

What should I try instead?




Aucun commentaire:

Enregistrer un commentaire