vendredi 1 novembre 2019

Adding or removing an array from or to a list of array

I want to do something like this, the code is

import numpy as np
import random
a = [np.array([2,4,5]), np.array([3,4,6]), np.array([3,7,8])]
b=np.array([4,6,7])
for i in range(5):
    e = random.choice(a)
    a.remove(e)
    a.append(b)

But we can't remove or add arrays like that. I want to remove the array e and add array b to a, so how can I do that?




Aucun commentaire:

Enregistrer un commentaire