Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Some 2x2 array
- (def data) (np.array [[0 1] [2 3]])
- ; Ugly as hell
- (def row-before (get data (, (slice 0 1))))
- (def col-before (get data (, (slice None) (slice 0 1))))
- ; The solution
- (defmacro get-slice [data &rest slices]
- (setv make-slice
- (fn [x]
- (cond
- [(= x []) `(slice None None)]
- [(coll? x) `(slice ~@x)]
- [True x])))
- `(get ~data (, ~@(list-comp (make-slice x) [x slices]))))
- ; Heaven.
- (def row-after (get-slice data [0 1]))
- (def col-after (get-slice data [] [0 1]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement