question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

np.random.choice doesn't want a to be empty

See original GitHub issue
while 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:closed
  • Created 5 years ago
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
eliorccommented, May 5, 2018

@pranavdogra7 , I believe this is fixed, please update your node2vec version to the lastest (0.1.2) and report if this was solved. Thanks

0reactions
pranavdogra7commented, Apr 29, 2018

With the previous file (case 1), you can use the below-mentioned code

with open("export.json") as file:
	g = json.load(file)

graph = json_graph.adjacency_graph(g)
nx.draw(graph)
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found