[Numpy-discussion] Matlab -> NumPy translation and indexing

Alan G Isaac aisaac at american.edu
Mon Mar 5 09:35:06 EST 2007


On 3/5/2007 2:13 PM, David Koch wrote: 
> - Given a matrix R, is there an equvialent to the Matlab 
> operation R(:,j) = [] (which removes column j and 
> "shrinks" the matrix? 


>>> help(numpy.delete)
Help on function delete in module numpy.lib.function_base:

delete(arr, obj, axis=None)
    Return a new array with sub-arrays along an axis deleted.

    Return a new array with the sub-arrays (i.e. rows or columns)
    deleted along the given axis as specified by obj

    obj may be a slice_object (s_[3:5:2]) or an integer
    or an array of integers indicated which sub-arrays to
    remove.

    If axis is None, then ravel the array first.

    Example:
    >>> arr = [[3,4,5],
              [1,2,3],
              [6,7,8]]

    >>> delete(arr, 1, 1)
    array([[3,5],
           [1,3],
           [6,8])
    >>> delete(arr, 1, 0)
    array([[3,4,5],
           [6,7,8]])

hth,
Alan Isaac







More information about the NumPy-Discussion mailing list