map for numarray and automatic calls of elements?
In my experience, when using Numeric (numpy), the following two features turned out to be very useful in many numerical operations. Please let me know if numarray already supports the features. Any comments are welcome. 1. A function like map but it returns an array directly, not a list. For instance, if we call the function as xmap,
f = lambda x: x+1 map(f, [1,2,3]) [2,3,4] xmap(f, [1,2,3]) # == array(map(f,[1,2,3])) array([2,3,4])
When dealing with a large volume of arrays, this function can save memory and improve speed significantly by skipping the creation of a list. 2. A way to call methods or attributes of object elements from an object array. For instance,
from datetime import date x = array([date(1990,1,1), date(2000,1,1)]) x.year array([1990, 2000])
If an object array is called by a methods or an attribute, which the array doesn't have, the array calls the methods or the attributes of its elements automatically and returns a collection of the results. Thanks. -- Daehyok Shin Geography Department University of North Carolina, Chapel Hill email: sdhyok@email.unc.edu
participants (1)
-
Shin