python - Using numpy.nditer in Hy -
in python, following code iterates numpy array (the loop), , values of numpy array changed:
import numpy a08_1 = numpy.arange(8).astype(numpy.uint8) # a08_1: array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint8) x in numpy.nditer(a08_1, op_flags=['readwrite']): x[...] = 255 if x == 1 else 0 # # a08_1: array([ 0, 255, 0, 0, 0, 0, 0, 0], dtype=uint8)
is possible in hy? can create iterator (numpy.nditer a08_1) not know how follow.
thanks.
equivalent hy looks this.
(import numpy) (setv a08-1 (-> (numpy.arange 8) (.astype numpy.uint8))) (for [x (numpy.nditer a08-1 :op-flags ["readwrite"])] (assoc x ellipsis (if (= x 1) 255 0)))
Comments
Post a Comment