logical count

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

londonphd
Posts: 37
Joined: Fri Oct 23, 2015 11:39 am

logical count

Postby londonphd » Mon May 16, 2016 5:55 am

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

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13586
Joined: Tue Sep 16, 2008 5:38 pm

Re: logical count

Postby EViews Gareth » Mon May 16, 2016 10:03 am

I don't follow

londonphd
Posts: 37
Joined: Fri Oct 23, 2015 11:39 am

Re: logical count

Postby londonphd » Mon May 16, 2016 11:27 am

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.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13586
Joined: Tue Sep 16, 2008 5:38 pm

Re: logical count

Postby EViews Gareth » Mon May 16, 2016 11:43 am

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

londonphd
Posts: 37
Joined: Fri Oct 23, 2015 11:39 am

Re: logical count

Postby londonphd » Mon May 16, 2016 11:51 am

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 :)

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13586
Joined: Tue Sep 16, 2008 5:38 pm

Re: logical count

Postby EViews Gareth » Mon May 16, 2016 12:02 pm

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.

londonphd
Posts: 37
Joined: Fri Oct 23, 2015 11:39 am

Re: logical count

Postby londonphd » Mon May 16, 2016 12:18 pm

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!

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: logical count

Postby EViews Glenn » Mon May 16, 2016 1:27 pm

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.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13586
Joined: Tue Sep 16, 2008 5:38 pm

Re: logical count

Postby EViews Gareth » Mon May 16, 2016 1:38 pm

Couldn't remember if @egt was in EV10 only :D


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests