[SciPy-user] New bmat constructor in SciPy
Perry Greenfield
perry at stsci.edu
Tue Sep 23 15:16:33 EDT 2003
> On Tue, 23 Sep 2003, Nils Wagner wrote:
>
> > In this context it would be nice to have a tool to remove
> > rows and columns of a matrix
> > In Matlab:
> >
> > > > a=rand(4,4)
> >
> > a =
> >
> > 0.9501 0.8913 0.8214 0.9218
> > 0.2311 0.7621 0.4447 0.7382
> > 0.6068 0.4565 0.6154 0.1763
> > 0.4860 0.0185 0.7919 0.4057
> >
> > use
> >
> > > > a(:,2)=[]
>
> I wonder if in Python
>
> >>> del a[:,2]
>
> would be possible. Currently Numeric raises ValueError, numarray raises
> TypeError and
> m=mat(a); del a[:,2]
> gives AttributeError: __delitem__ not found.
>
> Pearu
I've given this a tiny bit of thought. In principle there isn't
any reason why numeric arrays couldn't be resizable (or a subclass),
where they would have behavior similar to Python lists in this regard;
space is overallocated for arrays and so rows and columns may be added or
deleted. If there isn't enough space a new larger buffer is created and
the data copied, and if it shrinks a lot, a smaller buffer is created
and the larger released. But I don't think it is something we have the
resources (or need) to tackle in the near term.
Perry
More information about the SciPy-User
mailing list