Page 1 of 1

logical count

Posted: Mon May 16, 2016 5:55 am
by londonphd
Hi,

I want to count the number of observations that are greater than say a 100x4 matrix. The code will be used in a loop where the rows/columns of the matrix will be indexed i.e.loop goes over each element of the matrix. In each run of the loop, I want to count elements greater than 1 per row.
I tried the following code, it did not help.

Code: Select all

mat1(!i,1) = @sum(matname(!i,!j)>1)
Thanks

Re: logical count

Posted: Mon May 16, 2016 10:03 am
by EViews Gareth
I don't follow

Re: logical count

Posted: Mon May 16, 2016 11:27 am
by londonphd
I don't follow
Hello Gareth,

I have data that is stored in a 100x5 matrix. I want to count how many elements per row are greater than 1.

THanks.

Re: logical count

Posted: Mon May 16, 2016 11:43 am
by EViews Gareth
Brute force:

Code: Select all

vector(100) count for !i=1 to 100 !count = 0 for !j=1 to 5 if x(!i,!j)>1 then !count=!count+1 endif next count(!i) = !count next

Re: logical count

Posted: Mon May 16, 2016 11:51 am
by londonphd
Brute force:

Code: Select all

vector(100) count for !i=1 to 100 !count = 0 for !j=1 to 5 if x(!i,!j)>1 then !count=!count+1 endif next count(!i) = !count next
Wow, thanks. But this probably makes my already inefficient code a more inefficient one :)

Re: logical count

Posted: Mon May 16, 2016 12:02 pm
by EViews Gareth
If it is a one-off operation, then it probably takes 100th second, and the most efficient could be done in 1000th second. No big deal.

If you're doing it 1000 times, or as part of an optimization procedure, then yeah, you might want to think of something more efficient.

Re: logical count

Posted: Mon May 16, 2016 12:18 pm
by londonphd
If it is a one-off operation, then it probably takes 100th second, and the most efficient could be done in 1000th second. No big deal.

If you're doing it 1000 times, or as part of an optimization procedure, then yeah, you might want to think of something more efficient.
I cannot think of anything else. Will use it and have to just wait a few seconds I guess. Big Thank you!

Re: logical count

Posted: Mon May 16, 2016 1:27 pm
by EViews Glenn

Code: Select all

matrix(10000, 5) a nrnd(a) matrix(10000, 5) b b = 1 vector count count(1) = @sum(@egt(a, 1))
Not certain, but this should be faster.

Re: logical count

Posted: Mon May 16, 2016 1:38 pm
by EViews Gareth
Couldn't remember if @egt was in EV10 only :D