<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to remove a set of values from a matrix/vector? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-remove-a-set-of-values-from-a-matrix-vector/m-p/389289#M63941</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;DataM = J( 1067000, 8, Random Normal() ) || J( 1067000, 1, Random Binomial( 1, 0.07 ) );

DataM1 = DataM;

DataM2 = DataM;

Close( dt, nosave );

start = Tick Seconds();
foo = As Table( DataM, &amp;lt;&amp;lt;invisible );

foo &amp;lt;&amp;lt; select where( :col9 == 1 ) &amp;lt;&amp;lt; delete rows;
data2 = foo &amp;lt;&amp;lt; get as matrix;

data_table_method = Tick Seconds() - start;

start = Tick Seconds();
rr = Loc( DataM1[0, 9] == 1 );
DataM1[rr, 0] = [];
matrix_method1 = Tick Seconds() - start;


start = Tick Seconds();
rr = Loc( DataM2[0, 9] != 1 );
DataM2 = DataM2[rr, 0];
matrix_method2 = Tick Seconds() - start;

Show( data_table_method, matrix_method1, matrix_method2 );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;data_table_method = 1.0333333333333;
matrix_method1 = 49.166666666667;
matrix_method2 = 0.066666666666606;&lt;/PRE&gt;
&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/982"&gt;@Craige_Hales&lt;/a&gt;' method (matrix_method2) is the fastest.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was curious whether using a data table would be fast and, while it's 15x slower than matrix_method2, it's still pretty fast for this modestly-sized problem. I was then curious to see how long it would take if your data is already in a data table (avoiding the conversion to/from the data table) and it gets even faster.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;foo = As Table( DataM, &amp;lt;&amp;lt;invisible );
start = Tick Seconds();

foo &amp;lt;&amp;lt; select where( :col9 == 1 ) &amp;lt;&amp;lt; delete rows;
//data2 = foo &amp;lt;&amp;lt; get as matrix;

data_table_method2 = Tick Seconds() - start;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;data_table_method2 = 0.316666666666606&lt;/PRE&gt;</description>
    <pubDate>Fri, 28 May 2021 19:14:30 GMT</pubDate>
    <dc:creator>Jeff_Perkinson</dc:creator>
    <dc:date>2021-05-28T19:14:30Z</dc:date>
    <item>
      <title>How to remove a set of values from a matrix/vector?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-remove-a-set-of-values-from-a-matrix-vector/m-p/233109#M46225</link>
      <description>&lt;P&gt;Hi. &amp;nbsp;I have a large vector (i.e. 1-D matrix) of values, from which I'd like to remove a subset of the values, where the subset contains a non-sequential set of values from the original vector. &amp;nbsp;For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;largevect = [1,2,3,4,5]&lt;/P&gt;&lt;P&gt;subset = [2,5]&lt;/P&gt;&lt;P&gt;desired result = [1,3,4]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm wondering if a simple command or set of commands exists that could do this in JSL? &amp;nbsp;I could do this with a For Loop, but wondering if there's a more elegant or faster method?&lt;/P&gt;</description>
      <pubDate>Sun, 10 Nov 2019 20:52:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-remove-a-set-of-values-from-a-matrix-vector/m-p/233109#M46225</guid>
      <dc:creator>nikles</dc:creator>
      <dc:date>2019-11-10T20:52:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove a set of values from a matrix/vector?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-remove-a-set-of-values-from-a-matrix-vector/m-p/233119#M46226</link>
      <description>&lt;P&gt;Probably need more information to answer this well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are doing set operations, see&amp;nbsp;&lt;LI-MESSAGE title="JSL Set Operations" uid="39379" url="https://community.jmp.com/t5/Uncharted/JSL-Set-Operations/m-p/39379#U39379" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-blog-thread lia-fa-icon lia-fa-blog lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&amp;nbsp;for a way to do this with associative arrays:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// this would be a little more natural using lists
// or associative arrays, but it is easy to make an
// associative array set from a matrix:
largevect = [20, 30, 40, 50, 10];
subset = [20, 50];

aaBigSet = Associative Array( largevect );
aaSmallSet = Associative Array( subset );

// remove the small set from the big set
aaBigSet &amp;lt;&amp;lt; Remove( aaSmallSet );

// getkeys returns a list, make a matrix
result = Matrix( aaBigSet &amp;lt;&amp;lt; getkeys );

// the original order is lost, but the set is correct
show(result); // [10, 30, 40];&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is unclear in your example if &lt;EM&gt;subset&lt;/EM&gt;&amp;nbsp;is a list of values, or the indexes to values. If it is the indexes, and you could generate the set of indexes to keep instead of the set to remove, then it is as simple as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;largevect = [20, 30, 40, 50, 10];
keepers = [1,3,4];
desired result = largevect[ keepers ];
show(desiredResult); // [20, 40, 50];&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 May 2021 19:15:38 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-remove-a-set-of-values-from-a-matrix-vector/m-p/233119#M46226</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2021-05-28T19:15:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove a set of values from a matrix/vector?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-remove-a-set-of-values-from-a-matrix-vector/m-p/233812#M46348</link>
      <description>&lt;P&gt;Thanks Craige.&lt;/P&gt;&lt;P&gt;Your first assumption was correct: I wish to remove the literal values of 2 and 5 from the vector containing 1,2,3,4,5. &amp;nbsp;Another example to help clarify, I wish to remove this subset vector from largevect:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;largevect = [12, 189, 3, 78, -2]&lt;/P&gt;&lt;P&gt;subset = [189, -2]&lt;/P&gt;&lt;P&gt;dsired result = [12, 3, 78]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've not used AA's much, but I like this as a solution. &amp;nbsp;Thanks for the help!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2019 17:12:01 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-remove-a-set-of-values-from-a-matrix-vector/m-p/233812#M46348</guid>
      <dc:creator>nikles</dc:creator>
      <dc:date>2019-11-14T17:12:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove a set of values from a matrix/vector?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-remove-a-set-of-values-from-a-matrix-vector/m-p/389265#M63934</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/982"&gt;@Craige_Hales&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;do you have any thoughts on removing rows from a large matrix efficiently?&lt;/P&gt;&lt;P&gt;I have a situation where I have&amp;nbsp; data matrix that is &amp;gt; 1 million rows x 9 cols (&amp;nbsp; 1,604,736 x 9 in the example before me right now )&lt;/P&gt;&lt;P&gt;I need to remove some rows, actually &amp;gt; 78 k rows from it. Here's what I'm doing right now&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;	rr = Loc(DataM[0,4] == 1); 
	DataM[rr,0] = [];&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So I'm looking for cases where the 4th column = 1 and I want all those rows gone.&lt;/P&gt;&lt;P&gt;The Loc() line is super fast, ( &amp;lt; 0.05 sec ) but the following line is super slow ( 83 seconds )!&lt;/P&gt;&lt;P&gt;I'm using the JMP documentation where I read:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="fontstyle0"&gt;Deleting rows and columns is accomplished by assigning an empty matrix to that row or column.&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN class="fontstyle2"&gt;A[k, 0] = []; // deletes the kth row&lt;BR /&gt;A[0, k] = []; // deletes the kth column&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="fontstyle2"&gt;Maybe I'm just stuck because my data matrix is large&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's not clear to me whether I could use the Associative Array trick since I'm dealing with a matrix and not a vector&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Tom&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 May 2021 17:44:30 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-remove-a-set-of-values-from-a-matrix-vector/m-p/389265#M63934</guid>
      <dc:creator>tsl</dc:creator>
      <dc:date>2021-05-28T17:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove a set of values from a matrix/vector?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-remove-a-set-of-values-from-a-matrix-vector/m-p/389277#M63936</link>
      <description>Yes. Get the opposite loc, using !=, then&lt;BR /&gt;DataM = DataM[rr,0];&lt;BR /&gt;Should be 100x faster.&lt;BR /&gt;I suspect the way you are doing it recreates the array for each deleted row.</description>
      <pubDate>Fri, 28 May 2021 18:08:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-remove-a-set-of-values-from-a-matrix-vector/m-p/389277#M63936</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2021-05-28T18:08:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove a set of values from a matrix/vector?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-remove-a-set-of-values-from-a-matrix-vector/m-p/389289#M63941</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;DataM = J( 1067000, 8, Random Normal() ) || J( 1067000, 1, Random Binomial( 1, 0.07 ) );

DataM1 = DataM;

DataM2 = DataM;

Close( dt, nosave );

start = Tick Seconds();
foo = As Table( DataM, &amp;lt;&amp;lt;invisible );

foo &amp;lt;&amp;lt; select where( :col9 == 1 ) &amp;lt;&amp;lt; delete rows;
data2 = foo &amp;lt;&amp;lt; get as matrix;

data_table_method = Tick Seconds() - start;

start = Tick Seconds();
rr = Loc( DataM1[0, 9] == 1 );
DataM1[rr, 0] = [];
matrix_method1 = Tick Seconds() - start;


start = Tick Seconds();
rr = Loc( DataM2[0, 9] != 1 );
DataM2 = DataM2[rr, 0];
matrix_method2 = Tick Seconds() - start;

Show( data_table_method, matrix_method1, matrix_method2 );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;data_table_method = 1.0333333333333;
matrix_method1 = 49.166666666667;
matrix_method2 = 0.066666666666606;&lt;/PRE&gt;
&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/982"&gt;@Craige_Hales&lt;/a&gt;' method (matrix_method2) is the fastest.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was curious whether using a data table would be fast and, while it's 15x slower than matrix_method2, it's still pretty fast for this modestly-sized problem. I was then curious to see how long it would take if your data is already in a data table (avoiding the conversion to/from the data table) and it gets even faster.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;foo = As Table( DataM, &amp;lt;&amp;lt;invisible );
start = Tick Seconds();

foo &amp;lt;&amp;lt; select where( :col9 == 1 ) &amp;lt;&amp;lt; delete rows;
//data2 = foo &amp;lt;&amp;lt; get as matrix;

data_table_method2 = Tick Seconds() - start;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;data_table_method2 = 0.316666666666606&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 May 2021 19:14:30 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-remove-a-set-of-values-from-a-matrix-vector/m-p/389289#M63941</guid>
      <dc:creator>Jeff_Perkinson</dc:creator>
      <dc:date>2021-05-28T19:14:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove a set of values from a matrix/vector?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-remove-a-set-of-values-from-a-matrix-vector/m-p/389296#M63945</link>
      <description>&lt;P&gt;Thanks Jeff! 1000x is pretty good. I actually didn't realize a row could be assigned an empty matrix to delete it.&lt;/P&gt;&lt;P&gt;I already suggested to tech support that the doc needed to change or the slow method needed to be sped up.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 May 2021 20:27:49 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-remove-a-set-of-values-from-a-matrix-vector/m-p/389296#M63945</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2021-05-28T20:27:49Z</dc:date>
    </item>
  </channel>
</rss>

