[Numpy-discussion] Overlap arrays with "transparency"
Wed May 20 06:24:43 CDT 2009
Thank you for your help. :)
I used this :
try: NData[ (NData==transparent)[:len(OData)] ] = OData[ (NData==transparent)[:len(OData)] ]
That means overwrite all "transparent" data from NData with valid data from OData.
I am sure it's not the best method yet, but it's the only one that works.
--- On Mon, 5/18/09, Cristi Constantin <email@example.com> wrote:
From: Cristi Constantin <firstname.lastname@example.org>
Subject: [Numpy-discussion] Overlap arrays with "transparency"
To: "Numpy Discussion" <email@example.com>
Date: Monday, May 18, 2009, 5:37 AM
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...
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
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