Reputation: 23827
So, I want to do some reproducible stochastic simulations that I can share with others, for which I need to create a random state in numpy, using RS = np.random.RandomState(seed)
. So far so good.
But in my case, I may want to be able to choose a graph from a list.
import networkx as nx
import numpy as np
G = nx.Graph()
L = [G]
np.random.choice(L)
> mtrand.pyx in mtrand.RandomState.choice()
> ValueError: a must be 1-dimensional
This works with random
(as opposed to np.random
), but I see suggestions that random
may not give consistent results across different systems, even with the same seed.
Is there anything I can do to get numpy's random choice to work?
Upvotes: 0
Views: 139
Reputation: 323226
You can using index
random
then pick the value by its index
L[np.random.choice(np.array(len(L)),1)[0]]
Upvotes: 1