-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
339 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
language = "python" | ||
parent = "python" | ||
name = "numpy" | ||
title = "Numpy package" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,335 @@ | ||
language = "python" | ||
parent = "python.numpy" | ||
name = "numpy" | ||
title = "Vectors" | ||
description = "1D-array operations" | ||
|
||
[create] | ||
section = "Create" | ||
|
||
[create.undefined] | ||
what = "Undefined, length _n_" | ||
code = "np.empty(n)" | ||
details = "Warning: don't use the initial values" | ||
|
||
[create.constant.zero.float] | ||
what = "Float zeros, length _n_" | ||
code = "np.zeros(n)" | ||
|
||
[create.constant.zero.int] | ||
what = "Int zeros, length _n_" | ||
code = "np.zeros(n, dtype=np.int64)" | ||
|
||
[create.constant.one] | ||
what = "Ones, length _n_" | ||
code = "np.ones(n)" | ||
|
||
[create.constant.'true'] | ||
what = "True values, length _n_" | ||
code = "np.full(n, fill_value=True)" | ||
|
||
[create.constant.'false'] | ||
what = "False values, length _n_" | ||
code = "np.full(n, fill_value=False)" | ||
|
||
[create.constant.value] | ||
what = "Fill with value _v_" | ||
code = "np.full(n, fill_value=v)" | ||
|
||
[create.counter.end] | ||
what = "Increasing numbers [0, _b_-1]" | ||
code = "np.arrange(b)" | ||
|
||
[create.counter.range] | ||
what = "Increasing numbers [_a_, _b_]" | ||
code = "np.arrange(a, b)" | ||
|
||
[create.counter.step] | ||
what = "Numbers from _a_ to _b_ with step size _s_" | ||
code = "np.arrange(a, b, s)" | ||
|
||
[create.linspace.range] | ||
what = "Linear range from _a_ to _b_ of length _n_" | ||
code = "np.linspace(a, b, num=n)" | ||
|
||
[create.tuple] | ||
what = "From tuple" | ||
code = "np.array(tuple)" | ||
|
||
[create.list] | ||
what = "From list" | ||
code = "np.array(list)" | ||
|
||
[create.iter] | ||
what = "From iter" | ||
code= "np.fromiter(iter)" | ||
|
||
[create.iter.n] | ||
what = "From iter (max length _n_)" | ||
code = "np.fromiter(iter, count=n)" | ||
|
||
[create.concat] | ||
what = "From two vectors" | ||
code = "np.append(v1, v2)" | ||
|
||
[create.concat.2] | ||
code = "np.concatenate((v1, v2))" | ||
|
||
|
||
[test] | ||
section = "Test" | ||
|
||
[test.is] | ||
what = "Numpy array is vector" | ||
code = "v.ndim == 1" | ||
|
||
[test.equal] | ||
what = "Vectors are equal" | ||
code = "np.array_equal(v, v2)" | ||
|
||
[test.type.bool] | ||
what = "Logical type" | ||
code = "v.dtype == np.bool_" | ||
|
||
[test.type.float] | ||
what = "Float type" | ||
code = "v.dtype == np.float_" | ||
|
||
[test.type.int] | ||
what = "Integer type" | ||
code = "v.dtype == np.int_" | ||
|
||
[test.contains.'nan'] | ||
what = "Contains nan" | ||
code = "np.isnan(v).any()" | ||
|
||
[test.contains.'inf'] | ||
what = "Contains inf" | ||
code = "np.isinf(v).any()" | ||
|
||
[test.contains.value] | ||
what = "Contains value" | ||
code = "value in v" | ||
|
||
[test.missing.value] | ||
what = "Does not contain value" | ||
code = "value not in v" | ||
|
||
[test.finite.all] | ||
what = "All finite" | ||
code = "np.isfinite(v).all()" | ||
|
||
[test.value.all] | ||
what = "All elements are equal to value" | ||
code = "np.all(v == value)" | ||
|
||
[test.value.all.2] | ||
code = "(v == value).all()" | ||
|
||
[test.close.all] | ||
what = "All numerical elements are close to value" | ||
code = "np.all(np.isclose(v, value))" | ||
|
||
[test.equal.all] | ||
what = "All numerical elements are equal" | ||
code = "np.ptp(v) == 0" | ||
|
||
|
||
[update] | ||
section = "Update" | ||
description = "All operations are in-place" | ||
|
||
[update.elem.first] | ||
what = "Set first element" | ||
code = "v[0] = value" | ||
|
||
[update.elem.last] | ||
what = "Set last element" | ||
code = "v[-1] = value" | ||
|
||
[update.elem.index] | ||
what = "Set value of the _i_th element" | ||
code = "v[i] = value" | ||
|
||
[update.fill] | ||
what = "Fill with constant value" | ||
code = "v[:] = value" | ||
|
||
[update.fill.head] | ||
what = "Fill first _n_ values" | ||
code = "v[:n] = value" | ||
|
||
[update.sort.asc] | ||
what = "Sort elements ascending" | ||
code = "v.sort()" | ||
details = "NaNs are put last" | ||
|
||
[update.sort.desc] | ||
what = "Sort elements descending" | ||
code = "v[::-1].sort()" | ||
details = "Note that this puts NaNs first!" | ||
|
||
|
||
[get] | ||
section = "Get" | ||
|
||
[get.values.unique] | ||
what = "Unique values" | ||
code = "numpy.unique(v)" | ||
|
||
[get.values.unique.set] | ||
code = "set(v)" | ||
|
||
[get.values.unique.count] | ||
what = "Number of unique values" | ||
code = "len(numpy.unique(v))" | ||
|
||
[get.values.unique.counts] | ||
what = "Count per unique value" | ||
code = "np.unique(v, return_counts=True)" | ||
|
||
[get.values.nonzero.count] | ||
what = "Count non-zero values" | ||
code = "np.count_nonzero(v)" | ||
|
||
[get.bincount] | ||
what = "Count per positive integer from [0, max(v)]" | ||
code = "np.bincount(v)" | ||
details = "Elements must be nonnegative ints" | ||
|
||
[get.index.max] | ||
what = "Index of first max element" | ||
code = "np.argmax(v)" | ||
details = "Returns index of NaN if present!" | ||
|
||
[get.index.min] | ||
what = "Index of first min element" | ||
code = "np.argmin(v)" | ||
details = "Returns index of NaN if present!" | ||
|
||
|
||
[aggregate] | ||
section = "Aggregate" | ||
description = "See the API docs for a complete list" | ||
|
||
|
||
[derive] | ||
section = "Derive" | ||
|
||
[derive.map] | ||
section = "Map" | ||
|
||
[derive.map.truncate] | ||
what = "Clip (truncate) between [_a_, _b_ ]" | ||
code = "np.clip(v, a_min=a, a_max=b)" | ||
|
||
[derive.map.bin] | ||
what = "Bin index" | ||
code = "np.digitize(v, bins)" | ||
|
||
[derive.map.interp] | ||
what = "Piecewise-linear interpolation of coordinate mapping xp -> yp" | ||
code = "np.interp(v, xp, yp)" | ||
details = "No option for extrapolation!" | ||
|
||
[derive.map.interp.extra] | ||
what = "Piecewise-linear interpolation with extrapolation" | ||
code = """ | ||
f = scipy.interpolate.interp1d(xp, yp, fill_value = 'extrapolate') | ||
f(v) | ||
""" | ||
details = "Deprecated without replacement, lol" | ||
|
||
[derive.map.order.asc] | ||
what = "Ascending order (indices) of elements" | ||
code = "np.argsort(v)" | ||
|
||
[derive.map.order.desc] | ||
what = "Descending order (indices) of elements" | ||
code = "np.argsort(-v)" | ||
|
||
|
||
[derive.order] | ||
section = "Reorder elements" | ||
|
||
[derive.order.reverse] | ||
what = "Reverse elements" | ||
code = "v[::-1]" | ||
|
||
[derive.order.reverse.flip] | ||
code = "np.flip(v)" | ||
|
||
[derive.order.shift] | ||
what = "Shift elements forwards, with roll-over" | ||
code = "np.roll(v, 1)" | ||
|
||
[derive.order.shift.back] | ||
what = "Shift elements backwards, with roll-over" | ||
code = "np.roll(v, -1)" | ||
|
||
[derive.order.sort] | ||
what = "Sort ascending" | ||
code = "np.sort(v)" | ||
details = "NaNs are last" | ||
|
||
[derive.order.sort.desc] | ||
what = "Sort descending" | ||
code = "v[np.argsort(-v)]" | ||
details = "NaNs are last" | ||
|
||
|
||
[derive.shrink] | ||
section = "Shrink" | ||
|
||
[derive.shrink.diff] | ||
what = "Pairwise difference to next element" | ||
code = "np.diff(v)" | ||
details = "_n-1_ elements" | ||
|
||
[derive.shrink.diff.lag] | ||
what = "Pairwise difference between elements with given lag" | ||
code = "np.diff(v, n=lag)" | ||
|
||
|
||
[derive.grow] | ||
section = "Grow" | ||
|
||
[derive.grow.pad] | ||
what = "Pad with value" | ||
code = "np.pad(v, pad_width=1, constant_values=v)" | ||
|
||
[derive.grow.pad.outer] | ||
what = "Pad with outer elements" | ||
code = "np.pad(v, pad_width=1, mode='edge')" | ||
|
||
[derive.grow.rep] | ||
what = "Replicate _n_ times" | ||
code = "np.repeat(v, n)" | ||
|
||
[derive.grow.append] | ||
what = "Append vector" | ||
code = "np.append(v1, v2)" | ||
|
||
[derive.grow.concat] | ||
what = "Append vectors" | ||
code = "np.concatenate((v1, v2, v3))" | ||
|
||
|
||
[convert] | ||
section = "Convert" | ||
|
||
[convert.bytes] | ||
what = "Bytes" | ||
code = "v.tobytes()" | ||
|
||
[convert.tuple] | ||
what = "Tuple" | ||
code = "tuple(v)" | ||
|
||
[convert.list] | ||
what = "List" | ||
code = "v.tolist()" | ||
|
||
[convert.set] | ||
what = "Set" | ||
code = "set(v)" |