In the following code in python:
import numpy as np
a = np.random.normal(2, 0.1, 10)
c = [0,1,2,3,4,5,6,7,8,9]
b = [2,4]
print(a[b])
print(c[b])
Why print(a[b]) can be executed but an error message is shown for print(c[b])?
This type of indexing only works for numpy.ndarray and c is just a python list so you can't index it like numpy.ndarray. You can convert it to numpy array first then use your indexing.
c = np.array(c)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With