[Numpy-discussion] question/request with Numeric compress and putmask
vineet at eswap.com
Sun Feb 1 09:08:13 CST 2004
I'm using the Numeric arrays for financial data elements. I'm interfacing
with an external c library which does not support invalid elements. To get
around this I maintain a separate mask array in my python class which
denotes which elements are valid. I then use the compress function with the
mask array to get an array with valid elements which I pass to the c
I was then going to use the putmask to assign the returned values to their
corresponding place in the original array. This obviously (after reading the
documentation) is not going to work.
financial_data = [10, 11, 22, 33, INVALID, INVALID, 44, 55]
full_return_value = INVALID+zeros(lenfinancial_data)
my_mask = [1, 1, 1, 1, 0, 0, 1, 1]
compressed_data = compress(financiali_data, my_mask)
[10, 11, 22, 33, 44, 55]
return_value = some_c_function(compressed_data)
Now the problem I have is copying the values in return_value to their
original place in the financial_data. I was happily going to use putmask
till about an hour back when I found out that this is not going to work.
What I would like to do is:
putmask(full_return_value, my_mask, return_value)
where return_value is treated like a list so that every 1 that is found in
my_mask the next element in return_value is used. Is their anything that
I've looked at Masked Array. I don't like the fact that it return copies of
data and not references. I'm also unsure on how to pass it to c functions
(since it is a pure python package).
Any suggestions? and thanks for any help.
More information about the Numpy-discussion