Hi Dominic, The fastest way is to do this would be to grap the Array_Descriptor.Array_View_Pointer (see e.g. primer/pwave.C) and index the array as a C array. This would also avoid extra memory required by the solutions below. ...Bill #DOMINIC DENVER JOHN CHANDAR# wrote:
Hi Slava, Thanks for the idea ! .. Ive implemented this and its perfect .. Regards, Dominic-----Original Message----- From: overture-bounce@xxxxxxxxxxxxx [mailto:overture-bounce@xxxxxxxxxxxxx] On Behalf Of Viacheslav Merkin Sent: Tuesday, April 21, 2009 8:16 PM To: overture@xxxxxxxxxxxxx Subject: [overture] Re: A++ : Finding non-zeros in an array Hi Dominic, You could probably do something like this: where ( X != 0) { intArray mask = 1; RealArray Y=X } int N_nonzeros = sum(mask); Y.reshape(N_nonzeros); I don't remember the exact P++ usage for the sum() and the reshape() functions, but something like this should work, I think. Regards, Slava On Apr 21, 2009, at 7:25 AM, #DOMINIC DENVER JOHN CHANDAR# wrote:Hi,I have an array of the form X = { P , P, P , P, A, A, A, P, P , P, A , A, A}P : finite value exists A : value is zeroI would like to create a new array called Y = { P,P,P....} which has all the non-zero entries. I will not know the number of non-zeros unless I look into the array.. Using a simple loop, I believe this can be achieved.. but for large amount of data, it takes time. What could be the simplest way of doingthis using A++ ? I tried something like : where ( X != 0) { RealArray Y=X }The non zero entries are there.. but the dimension of array Y is obviously that of X.. with the remaining padded with zeros. Is there away to redimension this.. keeping in mind that we dont know the size of Y ..Thanks, Dominic