Changes between Version 25 and Version 26 of coding_rules


Ignore:
Timestamp:
08/20/20 12:24:30 (5 years ago)
Author:
jdquinn
Comment:

Added documentation for sorting 2D structure by column

Legend:

Unmodified
Added
Removed
Modified
  • coding_rules

    v25 v26  
    132132|| `s=num2str(A)` || `s=str(A)` || convert numbers to character array ||
    133133
     134
    134135=== !NumPy/SciPy ===
    135136!NumPy and !SciPy are used extensively in the Python interface to ISSM to replicate MATLAB-native functionality. When translating modules or tests, for example, from MATLAB to Python, the following sources may come in handy:
     
    138139Some notable omissions in the above sources are as follows:
    139140||= '''MATLAB''' =||= '''!NumPy''' =||= '''Notes''' =||
     141|| `<<cell_array>>{:}`  || `<<np.ndarray>>.flatten()` || Flatten a MATLAB cell array or Python ndarray. ||
    140142|| `find(a>0.5)` || `np.where(a>0.5)[0]`[[BR]][[BR]]`np.where(a>0.5,a,a)[0]` || Find the indices where (a > 0.5).[[BR]][[BR]]When only the {{{condition}}} parameters is provided, this function is a shorthand for `np.asarray(condition).nonzero()`.[[BR]]Further, when working on a 1D array, this array must be passed in as a value for parameters `x` and `y` if the desired output is a single array of indices rather than a tuple of arrays.[[BR]][[BR]]Note as well that `a` must be of type `np.array` (or one of its subclasses): a {{{list}}} will not automatically be cast.[[BR]][[BR]]See also: https://numpy.org/doc/stable/reference/generated/numpy.where.html ||
    141143|| `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. ||
    142 || `<<cell_array>>{:}`  || `<<np.ndarray>>.flatten()` || Flatten a MATLAB cell array or Python ndarray. ||
     144|| `B=sortrows(A,column)` || `B = A[A[:,column].argsort()]` || sort rows of matrix or table (MATLAB), or 2D array (NumPy) in ascending order based on the elements in 'column' ||
     145
    143146== !Variable/Enum/Function Names ==
    144147