Skip to content Skip to sidebar Skip to footer

How To Index 0-d Array In Python?

This may be a well-known question stored in some FAQ but i can't google the solution. I'm trying to write a scalar function of scalar argument but allowing for ndarray argument. Th

Solution 1:

This will work fine in NumPy >= 1.9 (not released as of writing this). On previous versions you can work around by an extra np.asarray call:

x[np.asarray(x > 0)] = 0

Solution 2:


Post a Comment for "How To Index 0-d Array In Python?"