Home | Trees | Indices | Help |
|
---|
|
1 # Copyright (C) 2009-2011 Power System Engineering Research Center (PSERC) 2 # Copyright (C) 2011 Richard Lincoln 3 # 4 # PYPOWER is free software: you can redistribute it and/or modify 5 # it under the terms of the GNU General Public License as published 6 # by the Free Software Foundation, either version 3 of the License, 7 # or (at your option) any later version. 8 # 9 # PYPOWER is distributed in the hope that it will be useful, 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # GNU General Public License for more details. 13 # 14 # You should have received a copy of the GNU General Public License 15 # along with PYPOWER. If not, see <http://www.gnu.org/licenses/>. 16 17 """Indexes a matrix dimension. 18 """ 19 20 from numpy import ndim 2123 """Returns A with one of its dimensions indexed:: 24 25 B = get_reorder(A, idx, dim) 26 27 Returns A[:, ..., :, idx, :, ..., :], where dim determines 28 in which dimension to place the idx. 29 30 @author: Ray Zimmerman (PSERC Cornell) 31 @author: Richard Lincoln 32 """ 33 ndims = ndim(A) 34 if ndims == 1: 35 B = A[idx].copy() 36 elif ndims == 2: 37 if dim == 0: 38 B = A[idx, :].copy() 39 elif dim == 1: 40 B = A[:, idx].copy() 41 else: 42 raise ValueError, 'dim (%d) may be 0 or 1' % dim 43 else: 44 raise ValueError, 'number of dimensions (%d) may be 1 or 2' % dim 45 46 return B47
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Fri Jul 29 18:21:31 2011 | http://epydoc.sourceforge.net |