Vectors
1D-array operations
Create
| Action |
Code |
Details |
|
Undefined, length n
|
|
Warning: don't use the initial values |
|
Float zeros, length n
|
|
|
|
Int zeros, length n
|
np.zeros(n, dtype=np.int64)
|
|
|
Ones, length n
|
|
|
|
True values, length n
|
np.full(n, fill_value=True)
|
|
|
False values, length n
|
np.full(n, fill_value=False)
|
|
|
Fill with value v
|
|
|
|
Increasing numbers [0, b-1]
|
|
|
|
Increasing numbers [a, b]
|
|
|
|
Numbers from a to b with step size s
|
|
|
|
Linear range from a to b of length n
|
|
|
|
From tuple
|
|
|
|
From list
|
|
|
|
From iter
|
|
|
|
From iter (max length n)
|
np.fromiter(iter, count=n)
|
|
|
From two vectors
|
|
|
|
From two vectors
|
|
|
Test
| Action |
Code |
Details |
|
Numpy array is vector
|
|
|
|
Vectors are equal
|
|
|
|
All numerical elements are equal
|
|
|
|
Logical type
|
|
|
|
Float type
|
|
|
|
Integer type
|
|
|
|
Contains nan
|
|
|
|
Contains inf
|
|
|
|
Contains value
|
|
|
|
Does not contain value
|
|
|
|
All finite
|
|
|
|
All elements are equal to value
|
|
|
|
All elements are equal to value
|
|
|
|
All numerical elements are close to value
|
np.all(np.isclose(v, value))
|
|
| Action |
Code |
Details |
|
Number of elements
|
|
|
|
Hash
|
|
|
|
Unique values
|
|
|
|
Unique values
|
|
|
|
Number of unique values
|
|
|
|
Count per unique value
|
np.unique(v, return_counts=True)
|
|
|
Count non-zero values
|
|
|
|
Count per positive integer from [0, max(v)]
|
|
Elements must be nonnegative ints |
|
Index of first max element
|
|
Returns index of NaN if present! |
|
Index of first min element
|
|
Returns index of NaN if present! |
Aggregate
See the API docs for a complete list
Update
All operations are in-place
| Action |
Code |
Details |
|
Set first element
|
|
|
|
Set last element
|
|
|
|
Set value of the _i_th element
|
|
|
|
Fill with constant value
|
|
|
|
Fill first n values
|
|
|
Order
| Action |
Code |
Details |
|
Sort elements ascending
|
|
NaNs are put last |
|
Sort elements descending
|
|
Note that this puts NaNs first! |
Derive
Map
| Action |
Code |
Details |
|
Clip (truncate) between [a, b ]
|
np.clip(v, a_min=a, a_max=b)
|
|
|
Bin index
|
|
|
|
Piecewise-linear interpolation of coordinate mapping xp -> yp
|
|
No option for extrapolation! |
|
Piecewise-linear interpolation with extrapolation
|
f = scipy.interpolate.interp1d(xp, yp, fill_value = 'extrapolate')
f(v)
|
Deprecated without replacement, lol |
|
Ascending order (indices) of elements
|
|
|
|
Descending order (indices) of elements
|
|
|
Reorder elements
| Action |
Code |
Details |
|
Reverse elements
|
|
|
|
Reverse elements
|
|
|
|
Shift elements forwards, with roll-over
|
|
|
|
Shift elements backwards, with roll-over
|
|
|
|
Sort ascending
|
|
NaNs are last |
|
Sort descending
|
|
NaNs are last |
Shrink
| Action |
Code |
Details |
|
Pairwise difference to next element
|
|
n-1 elements |
|
Pairwise difference between elements with given lag
|
|
|
Grow
| Action |
Code |
Details |
|
Pad with value
|
np.pad(v, pad_width=1, constant_values=v)
|
|
|
Pad with outer elements
|
np.pad(v, pad_width=1, mode='edge')
|
|
|
Replicate n times
|
|
|
|
Append vector
|
|
|
|
Append vectors
|
np.concatenate((v1, v2, v3))
|
|
Convert
| Action |
Code |
Details |
|
Bytes
|
|
|
|
Tuple
|
|
|
|
List
|
|
|
|
Set
|
|
|