Re: [Scilab-users] mean of elements corresponding element is "true"

2018-03-04 Thread Rafael Guerra

"Indeed. This is basically what nanmean()  does, managing in addition cases 
where no components remain on a range (all "%F")."
If all components are %F then the results in Scilab 6 for both solutions are 
%nan, which is convenient.
(Scilab 5 requires additional attention because of division by zero errors, 
though)

___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] mean of elements corresponding element is "true"

2018-03-04 Thread Rafael Guerra
Hermes,

With your solution all false elements (zeros) get averaged with the true ones.
The averaging should be done only over the true-entries.

Regards,
Rafael 

-Original Message-
From: users [mailto:users-boun...@lists.scilab.org] On Behalf Of Hermes
Sent: Sunday, March 04, 2018 10:10 AM
To: users@lists.scilab.org
Subject: Re: [Scilab-users] mean of elements corresponding element is "true"

how about this way:

n=10;
boolean_M=rand(n,n)>0.5;
disp(boolean_M)
A=rand(n,n);
disp(A);
x_V=mean(boolean_M.*A,'r')
disp(x_V)

Hermes



--
Sent from: 
http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users
___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] mean of elements corresponding element is "true"

2018-03-04 Thread Hermes
how about this way:

n=10;
boolean_M=rand(n,n)>0.5;
disp(boolean_M)
A=rand(n,n);
disp(A);
x_V=mean(boolean_M.*A,'r')
disp(x_V)

Hermes



--
Sent from: 
http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] mean of elements corresponding element is "true"

2018-03-03 Thread Samuel Gougeon

Le 03/03/2018 à 13:15, Rafael Guerra a écrit :


An alternative solution:

n=10;

M=bool2s(rand(n,n)>0.5);/// Boolean to zero-ones matrix/

A=rand(n,n);

x=sum(A.*M,'r')./sum(M,'r');



Indeed. This is basically what nanmean()  does, managing in addtition 
cases where no components remain on a range (all "%F").


___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] mean of elements corresponding element is "true"

2018-03-03 Thread fujimoto2005
Dear Rafael,

Thank you for another excellent solution.

Best regards



--
Sent from: 
http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] mean of elements corresponding element is "true"

2018-03-03 Thread Rafael Guerra
An alternative solution:
n=10;
M= bool2s(rand(n,n)>0.5);  // Boolean to zero-ones matrix
A= rand(n,n);
x=  sum(A.*M,'r') ./ sum(M,'r');


Regards,
Rafael
___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] mean of elements corresponding element is "true"

2018-03-02 Thread fujimoto2005
Dear Samuel

Thank you for your answer.

Best regards



--
Sent from: 
http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] mean of elements corresponding element is "true"

2018-03-02 Thread Samuel Gougeon

Le 02/03/2018 à 16:54, Samuel Gougeon a écrit :

Le 02/03/2018 à 16:40, fujimoto2005 a écrit :

In the attached code,"boolean_M" is a random Boolean matrix.
I want to get the average of each column of A whose corresponding element of
boolean_M has "true" as row vector x_V, but it does not work.
Where am I wrong?
n=10;
boolean_M=rand(n,n)>0.5;
disp(boolean_M)
A=rand(n,n);
disp(A);
x_V=mean(A(boolean_M),'r');


Instead, you may use
n  =  5;
boolean_M  =  rand(n,n)>0.5
A  =  grand(n,n,"uin",0,9)
A(boolean_M)  =  %nan
nanmean(A,"r")
--> n = 5;
--> boolean_M = rand(n,n)>0.5
 boolean_M  =
  T F F F T
  T T T T T
  T T F T T
  F T F T F
  F F T T F

--> A = grand(n,n,"uin",0,9)
 A  =
   6.   2.   5.   4.   6.
   6.   9.   3.   6.   5.
   3.   9.   3.   5.   4.
   0.   8.   7.   0.   7.
   1.   6.   8.   7.   2.

--> A(boolean_M) = %nan


or
--> A(~boolean_M) = %nan

to stick to your requirement


___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] mean of elements corresponding element is "true"

2018-03-02 Thread Samuel Gougeon

Le 02/03/2018 à 16:40, fujimoto2005 a écrit :

In the attached code,"boolean_M" is a random Boolean matrix.
I want to get the average of each column of A whose corresponding element of
boolean_M has "true" as row vector x_V, but it does not work.
Where am I wrong?
n=10;
boolean_M=rand(n,n)>0.5;
disp(boolean_M)
A=rand(n,n);
disp(A);
x_V=mean(A(boolean_M),'r');


Instead, you may use

n  =  5;
boolean_M  =  rand(n,n)>0.5
A  =  grand(n,n,"uin",0,9)
A(boolean_M)  =  %nan
nanmean(A,"r")

--> n = 5;
--> boolean_M = rand(n,n)>0.5
 boolean_M  =
  T F F F T
  T T T T T
  T T F T T
  F T F T F
  F F T T F

--> A = grand(n,n,"uin",0,9)
 A  =
   6.   2.   5.   4.   6.
   6.   9.   3.   6.   5.
   3.   9.   3.   5.   4.
   0.   8.   7.   0.   7.
   1.   6.   8.   7.   2.

--> A(boolean_M) = %nan
 A  =
   Nan   2.5.4.Nan
   Nan   Nan   Nan   Nan   Nan
   Nan   Nan   3.Nan   Nan
   0.Nan   7.Nan   7.
   1.6.Nan   Nan   2.

--> nanmean(A,"r")
 ans  =
   0.5   4.   5.   4.   4.5

Samuel

___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


[Scilab-users] mean of elements corresponding element is "true"

2018-03-02 Thread fujimoto2005
In the attached code,"boolean_M" is a random Boolean matrix.
I want to get the average of each column of A whose corresponding element of
boolean_M has "true" as row vector x_V, but it does not work.
Where am I wrong?

Best regards
test_meanWtboolean.sce
  




--
Sent from: 
http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users