Calculate a vector of miniums from a 2 dimentional matrixI am looking for a simple method to take a 2xn matrix and product a vector where each element in the vector is the minimum value for each row in the 2xn matrix
a=[ 1 4, 3 2, 5 6]
// the final result needs to be
[1, 2, 5]
Looping through matrix "a" can easily do this, but......I am hoping someone out there is more fluent in matrices that may have a more efficient solution
Data TableScriptingRe: Calculate a vector of miniums from a 2 dimentional matrixHi Jim,
m = [1 4, 3 2, 5 6];
v = Transpose( V Min( Transpose( m ) ) ); // VMin( m`)`
Re: Calculate a vector of miniums from a 2 dimentional matrixexcellent...Re: Calculate a vector of miniums from a 2 dimentional matrixI knew there was a function but I couldn't find it, so I did it step by step using matrix operations. Touché @gzmorgan0 !
Names Default to Here( 1 );
// define 2xn data matrix
a = [ 1 4, 3 2, 5 6];
// compute row-wise differences as a vector
b = a[0,1] - a[0,2];
// determine deficit in first column of data matrix
c = b < 0;
// determine deficit in second column of data matrix
d = !c;
// create conforming matrix of deficits
e = c || d;
// multiply to get minimum value
f = a * e`;
// extract minimum value from diagonal elements
Vec Diag( f );
I doubt that my way is more efficient than iterating over the rows of the data matrix. I am sure it is not more efficient than V Min()!
Re: Calculate a vector of miniums from a 2 dimentional matrixThis set of functions all work on the vertical dimension of a matrix and can use the same technique to get a horizontal version.
scripting index looking at functions that start with V
Re: Calculate a vector of miniums from a 2 dimentional matrixWow! I hope you are doing @DonMcCormack 's challenges! I'm still going to need to work through that a bit longer.