[Numpy-discussion] Most efficient trim of arrays
Mark Janikas
mjanikas at esri.com
Tue Dec 14 13:20:00 EST 2010
Hello All,
I was wondering what the best way to trim an array based on some values I do not want.... I could use NUM.where or NUM.take... but let me give you an example:
import numpy as NUM
n = 100 (Length of my dataset)
data = NUM.empty((n,), float)
badRecords = []
for ind, record in enumerate(records):
if record == someValueIDOntWant:
badRecords.append(ind)
else:
data[ind] = record
Now, I want to "trim" my array using badRecords. I guess I want to avoid copying. Any thoughts on the best way to do it? I do not want to use lists and then subsequently array the result as it is nice to pre-allocate the space.
Thanks much,
MJ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20101214/f8137f80/attachment.html>
More information about the NumPy-Discussion
mailing list