[overture] A++ : Finding non-zeros in an array

  • From: "#DOMINIC DENVER JOHN CHANDAR#" <DOMI0002@xxxxxxxxxx>
  • To: <overture@xxxxxxxxxxxxx>
  • Date: Tue, 21 Apr 2009 19:25:19 +0800

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 zero
 
I 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 doing
this 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 a
way to redimension this.. keeping in mind that we dont know the size of
Y ..
 
Thanks,
Dominic
 

Other related posts: