indexing

Numpy extract row, column and value from a matrix

半世苍凉 提交于 2019-12-23 01:27:10
问题 I have a matrix, and I want to write a script to extract values which are bigger than zero, its row number and column number(because the value belongs to that (row, column)), and here's an example, from numpy import * import numpy as np m=np.array([[0,2,4],[4,0,4],[5,4,0]]) index_row=[] index_col=[] dist=[] I want to store the row number in index_row , the column number in index_col , and the value in dist . So in this case, index_row = [0 0 1 1 2 2] index_col = [1 2 0 2 0 1] dist = [2 4 4 4

Fixing array indices in Python

戏子无情 提交于 2019-12-23 00:25:18
问题 I'd like to have arrays that start from say an index of 4 and go to 9. I'm not interested in creating memory space for < 4, so how is best to proceed? My 2D code is as follows: arr = [[ 0 for row in range(2)] for col in range(1, 129)] >>> arr[0][0] = 1 >>> arr[128][0] = 1 Traceback (most recent call last): File "<stdin>", line 1, in ? IndexError: list index out of range >>> arr[127][0] = 1 How can selectively just use the specific range i.e. where the last index runs from 1 to 128 inclusive

Deny all files except the index using apache

寵の児 提交于 2019-12-22 22:58:48
问题 Here's my .htaccess <Files *> Order Deny,Allow Deny from all </Files> <Files index.php> Order Deny,Allow Allow from all </Files> This is not working, cause if I type the hostname in my browser, it serves the index.php but apache doesn't seem to apply the Files instructions and instead returns a non-allowed file access page, I need typing the fullname document (e.g. 'index.php') to make it work. which is not really convenient... how to proceed if I want users only access index files of each

Deny all files except the index using apache

我是研究僧i 提交于 2019-12-22 22:58:07
问题 Here's my .htaccess <Files *> Order Deny,Allow Deny from all </Files> <Files index.php> Order Deny,Allow Allow from all </Files> This is not working, cause if I type the hostname in my browser, it serves the index.php but apache doesn't seem to apply the Files instructions and instead returns a non-allowed file access page, I need typing the fullname document (e.g. 'index.php') to make it work. which is not really convenient... how to proceed if I want users only access index files of each

Better way to extract all the rows from a Matrix A that contain an element of a matrix B

二次信任 提交于 2019-12-22 18:42:47
问题 Matrix A is my starting matrix it holds the data logged from my MPU6050 and GPS on an SD Card (Latitude, Longitude, Time, Ax, Ay, Az, Gx,Gy,Gz). I calculated the standard deviation of Az for window size of 5 and identified all the elements that satisfy a condition (>threshold). Then in a matrix "large_windows" i stored the index of all the Az in the window that satisfy the condition. From matrix "large_windows" i calculated a new matrix B with all the rows from matrix A that contain the

Selecting specific range of columns from .CSV file [duplicate]

大兔子大兔子 提交于 2019-12-22 18:06:05
问题 This question already has answers here : How to make a flat list out of list of lists? (46 answers) Closed last year . I have a CSV file which has 78000 columns. I am trying to select the columns 2-100, 102-200, and the last 300 columns. The rest of the columns need to be skipped. I have used numpy.loadtxt to select range of columns: numpy.loadtxt(input_file_name, delimiter=",", skiprows = 1, usecols=range(1,99)) How can we select blocks of columns doing something similar, like: numpy.loadtxt

Fast query in formatted data

情到浓时终转凉″ 提交于 2019-12-22 17:58:20
问题 In my program I need to query through metadata. I read data into numpy record array A from csv-like text file ** without duplicate rows**. var1|var2|var3|var4|var5|var6 'a1'|'b1'|'c1'|1.2|2.2|3.4 'a1'|'b1'|'c4'|3.2|6.2|3.2 'a2'|''|'c1'|1.4|5.7|3.8 'a2'|'b1'|'c2'|1.2|2.2|3.4 'a3'|''|'c2'|1.2|2.2|3.4 'a1'|'b2'|'c4'|7.2|6.2|3.2 ... There are millions of rows and the query in nested loops can be up to billion times (mostly matching the first 3 columns), so the efficiency becomes critical. There

How do I optimize a database for superstring queries?

大兔子大兔子 提交于 2019-12-22 16:57:47
问题 So I have a database table in MySQL that has a column containing a string. Given a target string, I want to find all the rows that have a substring contained in the target, ie all the rows for which the target string is a superstring for the column. At the moment I'm using a query along the lines of: SELECT * FROM table WHERE 'my superstring' LIKE CONCAT('%', column, '%') My worry is that this won't scale. I'm currently doing some tests to see if this is a problem but I'm wondering if anyone

How do you create a Postgresql JSONB array in array index?

帅比萌擦擦* 提交于 2019-12-22 12:32:39
问题 I have structure like this: user_id, a. a is of type jsonb and has the following structure: { b: [ {ids: [1,2,3,4]}, {ids: [2,3,4]}, {ids: [1,2,4]}, ... ] } How would I make an index that enabled me to find all users (user_id) that has a certain id in the ids list? 回答1: Is a GIN index what you want? It seems that you first need to organized the IDs into a form that is more tractable. I'm more familiar with Python than I am with the PostgreSQL ways of manipulating JSON, so I used PL/Python for

How do you create a Postgresql JSONB array in array index?

谁都会走 提交于 2019-12-22 12:32:15
问题 I have structure like this: user_id, a. a is of type jsonb and has the following structure: { b: [ {ids: [1,2,3,4]}, {ids: [2,3,4]}, {ids: [1,2,4]}, ... ] } How would I make an index that enabled me to find all users (user_id) that has a certain id in the ids list? 回答1: Is a GIN index what you want? It seems that you first need to organized the IDs into a form that is more tractable. I'm more familiar with Python than I am with the PostgreSQL ways of manipulating JSON, so I used PL/Python for