np.random.choice doesn't want a to be empty
See original GitHub issuewhile len(walk) < walk_length:
walk_options = d_graph[walk[-1]][neighbors_key]
if len(walk) == 1: # For the first step
walk_to = np.random.choice(walk_options, size=1)[0]
else:
probabilities = d_graph[walk[-1]][probabilities_key][walk[-2]]
walk_to = np.random.choice(walk_options, size=1, p=probabilities)[0]
This is giving error. Can you please look into it ? In some cases, walk_options is an empty list and hence the error. Is there any way around? I tried putting if conditions for empty case but it’s not working.
Issue Analytics
- State:
- Created 5 years ago
- Comments:16 (8 by maintainers)
Top Results From Across the Web
np.random.choice not returning correct weights when vectorized
np.random.choice returns one value, so you assign the same value to all null-cells. Therefore, you have first to find all null-values and ...
Read more >numpy.random.choice — NumPy v1.24 Manual
Parameters: a1-D array-like or int. If an ndarray, a random sample is generated from its elements. If an int, the random sample is...
Read more >random — Generate pseudo-random numbers — Python 3.11 ...
This module implements pseudo-random number generators for various distributions. For integers, there is uniform selection from a range. For sequences, there is ...
Read more >Python random choice() function to select a random item from ...
Here seq can be a list, tuple, string, or any iterable like range ... np.random.choice(), Return random choice from a multidimensional array.
Read more >Generating Random Data in Python (Guide)
To pick a random element from a non-empty sequence (like a list or a tuple), you can use random.choice() . There is also...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@pranavdogra7 , I believe this is fixed, please update your node2vec version to the lastest (0.1.2) and report if this was solved. Thanks
With the previous file (case 1), you can use the below-mentioned code