involucelate - 1 year ago 75

Python Question

I'm looking for a numpy function that will do the equivalent of:

`indices = set([1, 4, 5, 6, 7])`

zero = numpy.zeros(10)

for i in indices:

zero[i] = 42

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

You can just give it a list of indices:

```
indices = [1, 4, 5, 6, 7]
zero = numpy.zeros(10)
zero[indices] = 42
```

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**