ArraySliceWithStride.swift
struct ArraySliceWithStride<Element> {
typealias Base = Array<Element>
private let _base: Base
private let _slice: Array<Any>.Slice
private var _start: Int { return _slice.start! }
let count: Int
private var _stride: Int { return _slice.stride }
init(_ base: Base, from start: Base.Index?, to end: Base.Index?, by stride: Base.Index.Stride) {
self._base = base
This file has been truncated. show original
Numpy_vs_ArraySliceWithStride.md
# Comparison between Numpy and ArraySliceWithStride
| | NumPy | ArraySliceWithStride | Result |
|------------------------------------------------------|-----------------------------|----------------------------------------|----------------------------------|
| Array creation | `a = np.array(range(0,10))` | `var a = Array(0..<10)` | `[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]` |
| All sliced | `a[:]` | `a[.\|1]` | `[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]` |
| Sliced by 2 | `a[::2]` | `a[.\|2]` | `[0, 2, 4, 6, 8]` |
| Sliced from 2 | `a[2:]` | `a[2.~]` | `[2, 3, 4, 5, 6, 7, 8, 9]` |
| Sliced to the 2nd last index (-2) | `a[:-2]` | `a[.~(-2)]` | `[0, 1, 2, 3, 4, 5, 6, 7]` |
| Sliced from 2 to -2 | `a[2:-2]` | `a[2.~(-2)]` | `[2, 3, 4, 5, 6, 7]` |
This file has been truncated. show original