Note that there are some explanatory texts on larger screens.

plurals
  1. POdeleting rows in numpy array
    primarykey
    data
    text
    <p>I have an array that might look like this:</p> <pre><code>ANOVAInputMatrixValuesArray = [[ 0.96488889, 0.73641667, 0.67521429, 0.592875, 0.53172222], [ 0.78008333, 0.5938125, 0.481, 0.39883333, 0.]] </code></pre> <p>Notice that one of the rows has a zero value at the end. I want to delete any row that contains a zero, while keeping any row that contains non-zero values in all cells.</p> <p>But the array will have different numbers of rows every time it is populated, and the zeros will be located in different rows each time.</p> <p>I get the number of non-zero elements in each row with the following line of code:</p> <pre><code>NumNonzeroElementsInRows = (ANOVAInputMatrixValuesArray != 0).sum(1) </code></pre> <p>For the array above, <code>NumNonzeroElementsInRows</code> contains: [5 4]</p> <p>The five indicates that all possible values in row 0 are nonzero, while the four indicates that one of the possible values in row 1 is a zero.</p> <p>Therefore, I am trying to use the following lines of code to find and delete rows that contain zero values.</p> <pre><code>for q in range(len(NumNonzeroElementsInRows)): if NumNonzeroElementsInRows[q] &lt; NumNonzeroElementsInRows.max(): p.delete(ANOVAInputMatrixValuesArray, q, axis=0) </code></pre> <p>But for some reason, this code does not seem to do anything, even though doing a lot of print commands indicates that all of the variables seem to be populating correctly leading up to the code.</p> <p>There must be some easy way to simply "delete any row that contains a zero value."</p> <p>Can anyone show me what code to write to accomplish this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload