<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Thank you for your help. :)<br><br>I used this :<br>try: NData[ (NData==transparent)[:len(OData)] ] = OData[ (NData==transparent)[:len(OData)] ]<br>except: pass<br><br>That means overwrite all "transparent" data from NData with valid data from OData.<br>I am sure it's not the best method yet, but it's the only one that works.<br><br>--- On <b>Mon, 5/18/09, Cristi Constantin <i><darkgl0w@yahoo.com></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Cristi Constantin <darkgl0w@yahoo.com><br>Subject: [Numpy-discussion] Overlap arrays with "transparency"<br>To: "Numpy Discussion" <numpy-discussion@scipy.org><br>Date: Monday, May 18, 2009, 5:37 AM<br><br><div id="yiv258632864"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font-family: inherit;
font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit; -x-system-font: none;" valign="top">Good day.<br>I am working on this algorithm for a few weeks now, so i tried almost everything...<br>I want to overlap / overwrite 2 matrices, but completely ignore some values (in this case ignore 0)<br>Let me explain:<br><br>a = [<br>[1, 2, 3, 4, 5],<br>[9,7],<br>[0,0,0,0,0],<br>[5,5,5] ]<br><br>b = [<br>[0,0,9,9],<br>[1,1,1,1],<br>[2,2,2,2] ]<br><br>Then, we have:<br><br>a over b = [<br>[1,2,3,4,5],<br>[9,7,1,1],<br>[1,1,1,1,0],<br>[5,5,5,2] ]<br><br>b over a = [<br>[0,0,9,9,5],<br>1,1,1,1],<br>2,2,2,2,0],<br>5,5,5] ]<br><br>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.<br>I checked the documentation, i just need some tips.<br><br>TempA =
[[]]<br>#<br>One For Cicle in here to get the Element data...<br> Data =
vElem.data # This is a list of numpy ndarrays.<br> #<br> for nr_row in range( len(Data) ): # For each numpy ndarray (row) in Data.<br> #<br> NData = Data[nr_row] # New data, to be written over old data.<br> OData = TempA[nr_row:nr_row+1] or [[]] # This is old data. Can be numpy ndarray, or empty list.<br> OData = OData[0]<br> #<br> # NData must completely eliminate transparent pixels... here comes the algorithm... No algorithm
yet.<br> #<br> if len(NData) >= len(OData): <br> # If new data is longer than old data, old data will be completely overwritten.<br> TempA[nr_row:nr_row+1] = [NData]<br> else: # Old data is longer than new data ; old data cannot be null.<br> TempB = np.copy(OData)<br> TempB.put( range(len(NData)), NData )<br> #TempB[0:len(NData)-1] = NData # This returns "ValueError: shape mismatch: objects cannot be broadcast to a single shape"<br>
TempA[nr_row:nr_row+1] = [TempB]<br> del TempB<br> #<br> #<br>#<br>The result is stored inside TempA as list of numpy arrays.<br><br>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.<br>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.<br>Please, any suggestion is useful.<br><br>Thank you.</td></tr></tbody></table></div><br></blockquote></td></tr></table><br>