From: Aureli S. F. <Aur...@ip...> - 2001-03-19 20:05:27
|
Hello again, I have forgotten in my previous mail that I want the procedure to run independent of the value of N... So the value of N is not known during the implementation. Sorry about the duplication... >Hello! > >I have a N-dimensional array A and I want to operate in one of the axis >(k) with a 1 dimensional array (for instance, subtracting an array B of >length k). I have looked for some solutions in the manual and did not >found any. > >So after testing a lot I found following solution: > >A=Numeric.array(a) > >A.shape=(a1,a2,...,ak,...,aN) #where N is any int value > >B=Numeric.array(b) >B.shape=(ak,) > > >A_modified=Numeric.reshape(A, (a1*a2*...*aN,ak)) #ak is not included in >the product > >result=[] >for i in A_modified: > result.append(i - B) > > >and finally reshaping the result appropriately. But it does not seem >neither elegant nor simple. > >Is there any more elegant solution? The key point is: how to operate a N-D >array with a 1D in one determined axis? > >Thanks in advance. >Regards, >Aureli > ################################# Aureli Soria Frisch Fraunhofer IPK Dept. Pattern Recognition post: Pascalstr. 8-9, 10587 Berlin, Germany e-mail:au...@ip... fon: +49 30 39 00 61 50 fax: +49 30 39 17 517 ################################# |