One common array transformation is slicing: extracting sub-arrays by picking rows from each axis independently.
(Sequenceof Integer ): pick rows from an axis by index.
Slice : pick rows from an axis as with an in-range sequence.
Slice-Dots : preserve remaining adjacent axes
Integer : remove an axis by replacing it with one of its rows.
Slice-New-Axis : insert an axis of a given length.
Create Slice objects using :: and Slice-New-Axis objects using ::new . There is only one Slice-Dots object, namely ::... .
When slicing an array with n axes, unless a list of slice specifications contains ::... , it must contain exactly n slice specifications.
#(234)> arr- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes String))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array
#[#[#["000" "001" "002" "003"]
#["010" "011" "012" "013"]
#["020" "021" "022" "023"]]
#[#["100" "101" "102" "103"]
#["110" "111" "112" "113"]
#["120" "121" "122" "123"]]])
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes String))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array
#[#[#["000" "001" "002" "003"]
#["010" "011" "012" "013"]
#["020" "021" "022" "023"]]
#[#["100" "101" "102" "103"]
#["110" "111" "112" "113"]
#["120" "121" "122" "123"]]])
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes String))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array
#[#[#["100" "101" "102" "103"]
#["110" "111" "112" "113"]
#["120" "121" "122" "123"]]
#[#["000" "001" "002" "003"]
#["010" "011" "012" "013"]
#["020" "021" "022" "023"]]])
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes String))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #[#[#["000" "002"] #["020" "022"]] #[#["100" "102"] #["120" "122"]]])
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes String))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #[#[#[] #[] #[]] #[#[] #[] #[]]])
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes String))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array
#[#[#["000" "000" "001" "002" "002" "003"]
#["010" "010" "011" "012" "012" "013"]
#["020" "020" "021" "022" "022" "023"]]
#[#["100" "100" "101" "102" "102" "103"]
#["110" "110" "111" "112" "112" "113"]
#["120" "120" "121" "122" "122" "123"]]])
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes String))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array
#[#[#["100" "102"]
#["110" "112"]
#["120" "122"]]
#[#["000" "002"]
#["010" "012"]
#["020" "022"]]])
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes String))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array
#[#[#["000" "001" "002" "003"]
#["010" "011" "012" "013"]
#["020" "021" "022" "023"]]
#[#["100" "101" "102" "103"]
#["110" "111" "112" "113"]
#["120" "121" "122" "123"]]])
As a slice specification, a Slice object acts like the sequence object returned by in-range , but either start or end may be #f.
If start is #f, it is interpreted as the first valid axis index in the direction of step. If end is #f, it is interpreted as the last valid axis index in the direction of step.
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes String))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array
#[#[#["000" "001" "002" "003"]
#["010" "011" "012" "013"]
#["020" "021" "022" "023"]]
#[#["100" "101" "102" "103"]
#["110" "111" "112" "113"]
#["120" "121" "122" "123"]]])
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes String))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array
#[#[#["003" "002" "001" "000"]
#["013" "012" "011" "010"]
#["023" "022" "021" "020"]]
#[#["103" "102" "101" "100"]
#["113" "112" "111" "110"]
#["123" "122" "121" "120"]]])
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes String))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array
#[#[#["002" "003"]
#["012" "013"]
#["022" "023"]]
#[#["102" "103"]
#["112" "113"]
#["122" "123"]]])
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes String))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array
#[#[#["001" "003"]
#["011" "013"]
#["021" "023"]]
#[#["101" "103"]
#["111" "113"]
#["121" "123"]]])
As a slice specification, a Slice-Dots object represents any number of leftover, adjacent axes, and preserves them all.
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes String))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array
#[#[#["001" "003"]
#["011" "013"]
#["021" "023"]]
#[#["101" "103"]
#["111" "113"]
#["121" "123"]]])
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes String))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array
#[#[#["000" "001" "002" "003"]
#["010" "011" "012" "013"]
#["020" "021" "022" "023"]]])
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes String))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #[#[#["001"] #["011"] #["021"]] #[#["101"] #["111"] #["121"]]])
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes String))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #[#[#["001"] #["011"] #["021"]] #[#["101"] #["111"] #["121"]]])
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes String))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #[#[#["111"]]])
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes String))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #[#[#["111"]]])
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes String))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #[#[#["111"]]])
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes String))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #[#[#["111"]]])
All of the slice specifications so far preserve the dimensions of the array. Removing an axis can be done by using an integer as a slice specification.
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes String))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array
#[#["000" "001" "002" "003"]
#["010" "011" "012" "013"]
#["020" "021" "022" "023"]])
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes String))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #[#["010" "011" "012" "013"] #["110" "111" "112" "113"]])
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes String))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #[#["010" "011" "012" "013"] #["110" "111" "112" "113"]])
As a slice specification, (::new dk) inserts dk into the resulting array’s shape, in the corresponding axis position. The new axis has length dk, which must be nonnegative.
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes String))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array
#[#[#[#["000" "001" "002" "003"]
#["010" "011" "012" "013"]
#["020" "021" "022" "023"]]
#[#["100" "101" "102" "103"]
#["110" "111" "112" "113"]
#["120" "121" "122" "123"]]]])
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes String))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array
#[#[#[#["000" "001" "002" "003"]
#["010" "011" "012" "013"]
#["020" "021" "022" "023"]]
#[#["100" "101" "102" "103"]
#["110" "111" "112" "113"]
#["120" "121" "122" "123"]]]
#[#[#["000" "001" "002" "003"]
#["010" "011" "012" "013"]
#["020" "021" "022" "023"]]
#[#["100" "101" "102" "103"]
#["110" "111" "112" "113"]
#["120" "121" "122" "123"]]]])
- : #(struct:Array
(Indexes Index (Boxof Boolean) (-> Void) (-> Indexes String))
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:56:13 prop:equal+hash>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:55:13 prop:custom-write>
#<syntax:build/user/8.18/pkgs/math-lib/math/private/array/typed-array-struct.rkt:54:13 prop:custom-print-quotable>)
(array #[#[] #[]])