What is the fastest way of extracting indexes of non "-1"s from an array?

r indexing dataframe
indexing in r
r dataframe index column
r indexing 0 or 1
matlab matrix index
negative indexing in r
matrix indexing
matlab logical indexing

I have a numpy array with dimension 1500 x 3300. I want to fetch indexes of all values which have value greater than 0.40.

For example a sub-array:

a = [0,0.5,0.4,-1,-1,0.9,0.3,-1,0.7]

Desired result: [0,1,5,8]

I have written the following code, but it takes a lot of time to run. It takes 20 minutes to run on an array of dimension 1500 x 3300.

def non_zero(lst):
    """ return indexes of items which are not -1 and value is greater than 0.40 """
    return [i for i, e in enumerate(lst) if e > 0.40]

What can be the fastest alternative to do this?

Try the following directly in the 2D array:

i, j = np.where(np.array(lst) > 0.4)

What's the fastest way to extract non-zero indices from a byte array , With a byte array that is mostly zero, being a sparse array, you can take advantage of a 32 bit CPU by doing comparisons 4 bytes at a time. According to @xiaotian-peiI answer, I think it would be even better simply to insert pairs (key, index) in a deterministically balanced binary search tree (avl or red-black) sorted by keys; that takes O(n lg n). Then you traverse the binary tree inorder extracting the indexes, what takes O(n). Finally you free the tree, what takes O(n).

You can use np.argwhere to get the indexes.

import numpy as np
idx = np.argwhere(a != -1 & a > 0.4)

And of course, a!= -1 is not necessary..

Solved: Is there a way to know which fields were extracted, Re: Is there a way to know which fields were extracted at index-time vs search- time? javiergn So all that to say there's no "easy" answer. I think the best� 2) do I understand correctly that Pro*C program is the "fastest known file extractor to text" for Oracle? what about CTAS to external table (datapump)? where it goes in range of: - utl_file (slowest but really handy when it is "fast enough") - sqlplus - C

import numpy as np    
np.where(np.array(a) > 0.40)[0].tolist()

values > 0.40 are ofcourse > -1

Also Iam assuming that "a" is a list of numbers (not a list of lists)

Matrix Indexing in MATLAB - MATLAB & Simulink, MATLAB� has several indexing styles that are not only powerful and flexible, but The colon notation in MATLAB provides an easy way to extract a range of� Hi Tom, I am seeing a different trend growing up. Even the transaction tables are growing so fast that the batch jobs (summarizing the data of transaction tables into smaller version, for faster data retrieval), though scheduled at non business hours ( I wonder, in today's world which hour is not a business hour J ), stretching near to business hours.

Access Data in Tables - MATLAB & Simulink, Indexing into tables with parentheses, dot notation, and curly braces accesses table data in different ways. The rows of a table can have names, but row names are not required. To access table data, index into the rows and variables from the first table variable. Array, extracting data from one variable and specified rows. Oracle Best Fastest Way to Delete Data from Large Table Tips Oracle Database Tips by Donald Burleson October 25, 2015 Question: I have a very large table and I need to delete millions of rows from the table without the table fragmenting.

Indexing — R Spatial, There are multiple ways to access or replace values in vectors or other data It may, however, also lead to undetected errors, when this was not intended to happen. but it is generally easiest to use two numbers in a double index, the first for the And the elements can be extracted by their name, either as an index , or by� #1, Extract data in parallel; SSIS provides the way to pull data in parallel using Sequence containers in control flow. You can design a package in such a way that it can pull data from non-dependent tables or files in parallel, which will help to reduce overall ETL execution time.

3 Ways to extract unique values from a range in Excel, Advanced Filter; Index- Match Array Formula; Excel Macro (VBA); Remove Duplicates It is 1 when values of D2 and D3 are found and 0 where it is not found. The most easiest way to extract unique values from a range is to use " Remove� The other answers are excellent, although I’d like to take a slightly higher level view. Are you going to do this once, or multiple times? Do you have millions of records or a few thousand or how many?