Applies function fun() to each item of the sequence seq. An item corresponds to the last ndim dimensions of seq.
Parameters: | seq : array
fun : function
ndim : int
out_item_shape : tuple
|
---|---|
Returns: | out : array
|
Returns an index array that sorts the sequence seq. Works along rows if seq is two-dimensional.
Perform ar_out[indx] += ar_in, where items of ar_in corresponding to duplicate indices in indx are summed together.
Same as cycle, but with general sequences.
Example:
In [19]: c = combine( [[‘a’, ‘x’], [‘b’, ‘c’], [‘dd’]] )
In [20]: list(c) Out[20]: [[‘a’, ‘b’, ‘dd’], [‘a’, ‘c’, ‘dd’], [‘x’, ‘b’, ‘dd’], [‘x’, ‘c’, ‘dd’]]
Cycles through all combinations of bounds, returns a generator.
More specifically, let bounds=[a, b, c, ...], so cycle returns all combinations of lists [0<=i<a, 0<=j<b, 0<=k<c, ...] for all i,j,k,...
Examples: In [9]: list(cycle([3, 2])) Out[9]: [[0, 0], [0, 1], [1, 0], [1, 1], [2, 0], [2, 1]]
In [14]: list(cycle([3, 4])) [[0, 0], [0, 1], [0, 2], [0, 3], [1, 0], [1, 1], [1, 2], [1, 3], [2, 0], [2, 1], [2, 2], [2, 3]]
Fast determinant calculation of 3-dimensional array.
Parameters: | a : array
|
---|---|
Returns: | out : array
|
Computes dot product for each pair of items in the two sequences.
Equivalent to
>>> out = nm.empty((vec.shape[0], mtx.shape[1], vec.shape[2]),
>>> dtype=vec.dtype)
>>> for ir in range(mtx.shape[0]):
>>> out[ir] = nm.dot(mtx[ir], vec[ir])
Parameters: | mtx : array
vec : array
mode : one of ‘AB’, ‘ATB’, ‘ABT’, ‘ATBT’
|
---|---|
Returns: | out : array
|
Notes
Uses numpy.core.umath_tests.matrix_multiply() if available, which is much faster than the default implementation.
The default implementation uses numpy.sum() and element-wise multiplication. For r-D arrays (n_1, ..., n_r, ?, ?) the arrays are first reshaped to (n_1 * ... * n_r, ?, ?), then the dot is performed, and finally the shape is restored to (n_1, ..., n_r, ?, ?).
Insert a new axis of given length into an array using numpy stride tricks, i.e. no copy is made.
Parameters: | ar : array
axis : int
length : int
|
---|---|
Returns: | out : array
|
Examples
>>> import numpy as nm
>>> from sfepy.linalg import insert_strided_axis
>>> ar = nm.random.rand(2, 1, 2)
>>> ar
array([[[ 0.18905119, 0.44552425]],
[[ 0.78593989, 0.71852473]]])
>>> ar.shape
(2, 1, 2)
>>> ar2 = insert_strided_axis(ar, 1, 3)
>>> ar2
array([[[[ 0.18905119, 0.44552425]],
[[ 0.18905119, 0.44552425]],
[[ 0.18905119, 0.44552425]]],
[[[ 0.78593989, 0.71852473]],
[[ 0.78593989, 0.71852473]],
[[ 0.78593989, 0.71852473]]]])
>>> ar2.shape
(2, 3, 1, 2)
Returns an index array imap such that seq1[imap] == seq2, if both sequences have the same items - this is not checked by default!
In other words, finds the indices of items of seq2 in seq1.
Compute l2 norm of rows (axis=1) or columns (axis=0) of a 2D array.
n_item ... use only the first n_item columns/rows squared ... if True, return the norm squared