Changes between Version 36 and Version 37 of coding_rules


Ignore:
Timestamp:
08/21/20 17:09:00 (5 years ago)
Author:
jdquinn
Comment:

Clarification on np.where

Legend:

Unmodified
Added
Removed
Modified
  • coding_rules

    v36 v37  
    139139||= '''MATLAB''' =||= '''!NumPy''' =||= '''Notes''' =||
    140140|| `<<cell_array>>{:}`  || `<<np.ndarray>>.flatten()` || Flatten a MATLAB cell array or !NumPy `ndarray`. ||
    141 || `find(a>0.5)` || `np.where(a>0.5)[0]` || Find the indices where (a > 0.5).[[BR]][[BR]]When only the {{{condition}}} parameter is provided, this function is a shorthand for `np.asarray(condition).nonzero()`.[[BR]][[BR]]See also: [https://numpy.org/doc/stable/reference/generated/numpy.where.html | numpy.where - NumPy][[BR]][[BR]]NOTE:[[BR]]-`a` must be of type `np.array` (or one of its subclasses): a {{{list}}} will not automatically be cast.[[BR]]-Returns a tuple of arrays of indices, one for each dimension of the input array. Thus, when the input array is 1D, the indices can be retrieved simply by addressing the first element of the result (as in the example). ||
     141|| `find(a>0.5)` || `np.where(a>0.5)[0]` || Find the indices where (a > 0.5).[[BR]][[BR]]When only the {{{condition}}} parameter is provided, this function is a shorthand for `np.asarray(condition).nonzero()`.[[BR]][[BR]]See also: [https://numpy.org/doc/stable/reference/generated/numpy.where.html numpy.where - NumPy][[BR]][[BR]]NOTE:[[BR]]- `a` must be of type `np.array` (or one of its subclasses): a {{{list}}} will not automatically be cast.[[BR]]- Returns a tuple of arrays of indices, one for each dimension of the input array. Thus, when the input array is 1D, the indices can be retrieved simply by addressing the first element of the result (as in the example). ||
    142142|| `find('cond1'&'cond2')` || `np.where(np.logical_and.reduce(('cond1','cond2'))[0]` || Find the indices where `'cond1'` and `'cond2'` are met.[[BR]][[BR]]The same protocol can be followed for MATLAB's `|` by instead using `logical_or`.[[BR]][[BR]]More than two conditions may be compounded. ||
    143143|| `v=nonzeros(A)` || `v=A[np.nonzero(A)]` || Find the values of the nonzero elements ||