[Numpy-discussion] Overlap arrays with "transparency"
Mon May 18 07:37:09 CDT 2009
I am working on this algorithm for a few weeks now, so i tried almost everything...
I want to overlap / overwrite 2 matrices, but completely ignore some values (in this case ignore 0)
Let me explain:
a = [
[1, 2, 3, 4, 5],
b = [
Then, we have:
a over b = [
b over a = [
That means, completely overwrite one list of arrays over the other, not matter what values one has, not matter the size, just ignore 0 values on overwriting.
I checked the documentation, i just need some tips.
TempA = []
One For Cicle in here to get the Element data...
Data = vElem.data # This is a list of numpy ndarrays.
for nr_row in range( len(Data) ): # For each numpy ndarray (row) in Data.
NData = Data[nr_row] # New data, to be written over old data.
OData = TempA[nr_row:nr_row+1] or [] # This is old data. Can be numpy ndarray, or empty list.
OData = OData
# NData must completely eliminate transparent pixels... here comes the algorithm... No algorithm yet.
if len(NData) >= len(OData):
# If new data is longer than old data, old data will be completely overwritten.
TempA[nr_row:nr_row+1] = [NData]
else: # Old data is longer than new data ; old data cannot be null.
TempB = np.copy(OData)
TempB.put( range(len(NData)), NData )
#TempB[0:len(NData)-1] = NData # This returns "ValueError: shape mismatch: objects cannot be broadcast to a single shape"
TempA[nr_row:nr_row+1] = [TempB]
The result is stored inside TempA as list of numpy arrays.
I would use 2D arrays, but they are slower than Python Lists containing Numpy arrays. I need to do this overwrite in a very big loop and every delay is very important.
I tried to create a masked array where all "zero" values are ignored on overlap, but it doesn't work. Masked or not, the "transparent" values are still overwritten.
Please, any suggestion is useful.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion