Get the indices of N highest values in an ndarray

You can use numpy.argpartition on flattened version of array first to get the indices of top k items, and then you can convert those 1D indices as per the array’s shape using numpy.unravel_index: >>> arr = np.arange(100*100*100).reshape(100, 100, 100) >>> np.random.shuffle(arr) >>> indices = np.argpartition(arr.flatten(), -2)[-2:] >>> np.vstack(np.unravel_index(indices, arr.shape)).T array([[97, 99, 98], [97, 99, 99]]) … Read more

Oracle: function based index selective uniqueness

You would need something like CREATE UNIQUE INDEX fn_unique_idx ON table1 (CASE WHEN is_deleted=’N’ THEN id ELSE null END, CASE WHEN is_deleted=’N’ THEN name ELSE null END, CASE WHEN is_deleted=’N’ THEN type ELSE null END); An example of the constraint in action SQL> create table table1 ( 2 id number, 3 name varchar2(10), 4 type … Read more

Workaround in mysql for partial Index or filtered Index?

Filtered indexes could be emulated with function indexes and CASE expression(MySQL 8.0.13 and newer): CREATE TABLE t(id INT PRIMARY KEY, myColumn VARCHAR(100)); — NULL are not taken into account with `UNIQUE` indexes CREATE UNIQUE INDEX myIndex ON t((CASE WHEN myColumn <> ‘myText’ THEN myColumn END)); — inserting excluded value twice INSERT INTO t(id, myColumn) VALUES(1, … Read more