where

Numpy where returns empty array

点点圈 提交于 2020-08-07 09:47:29
问题 I have an array e.g. a = [5,1,3,0,2] I apply the where function: np.where(a == 2) The output is an empty array (array([], dtype=int64),) I found kind of the same problem here, but in my case it really dosen't make any sense or dose it? Btw. i'm on a Mac using Python 2.7.10 回答1: You're passing a list to where() function not a Numpy array. Use an array instead: In [20]: a = np.array([5,1,3,0,2]) In [21]: np.where(a == 2) Out[21]: (array([4]),) Also as mentioned in comments, in this case the

SQLite - Difference between IS and = (equals) in WHERE clause. (using JDBC PreparedStatement)

不打扰是莪最后的温柔 提交于 2020-04-11 12:42:47
问题 Edit: talking with a_horse_with_no_name I found that "IS" is a little bit different in SQLite allowing comparisons between NULL and values using "IS": stackoverflow.com/a/9102445/1470058. This clears up a lot of confusion for me. Thanks: The IS and IS NOT operators work like = and != except when one or both of the operands are NULL. In this case, if both operands are NULL, then the IS operator evaluates to 1 (true) and the IS NOT operator evaluates to 0 (false). If one operand is NULL and the

Oracle SQL Query Filter in JOIN ON vs WHERE

痴心易碎 提交于 2020-04-10 02:52:31
问题 For inner joins , is there any difference in performance to apply a filter in the JOIN ON clause or the WHERE clause? Which is going to be more efficient, or will the optimizer render them equal? JOIN ON SELECT u.name FROM users u JOIN departments d ON u.department_id = d.id AND d.name = 'IT' VS WHERE SELECT u.name FROM users u JOIN departments d ON u.department_id = d.id WHERE d.name = 'IT' Oracle 11gR2 回答1: There should be no difference. The optimizer should generate the same plan in both

Oracle SQL Query Filter in JOIN ON vs WHERE

前提是你 提交于 2020-04-10 02:52:08
问题 For inner joins , is there any difference in performance to apply a filter in the JOIN ON clause or the WHERE clause? Which is going to be more efficient, or will the optimizer render them equal? JOIN ON SELECT u.name FROM users u JOIN departments d ON u.department_id = d.id AND d.name = 'IT' VS WHERE SELECT u.name FROM users u JOIN departments d ON u.department_id = d.id WHERE d.name = 'IT' Oracle 11gR2 回答1: There should be no difference. The optimizer should generate the same plan in both

Pandas, loc vs non loc for boolean indexing

…衆ロ難τιáo~ 提交于 2020-03-13 07:50:10
问题 All the research I do point to using loc as the way to filter a dataframe by a col(s) value(s), today I was reading this and I discovered by the examples I tested, that loc isn't isn't really needed when filtering cols by it's values: EX: df = pd.DataFrame(np.arange(0, 20, 0.5).reshape(8, 5), columns=['a', 'b', 'c', 'd', 'e']) df.loc[df['a'] >= 15] a b c d e 6 15.0 15.5 16.0 16.5 17.0 7 17.5 18.0 18.5 19.0 19.5 df[df['a'] >= 15] a b c d e 6 15.0 15.5 16.0 16.5 17.0 7 17.5 18.0 18.5 19.0 19.5

How can you turn an index array into a mask array in Numpy?

五迷三道 提交于 2020-03-13 04:44:10
问题 Is it possible to convert an array of indices to an array of ones and zeros, given the range? i.e. [2,3] -> [0, 0, 1, 1, 0], in range of 5 I'm trying to automate something like this: >>> index_array = np.arange(200,300) array([200, 201, ... , 299]) >>> mask_array = ??? # some function of index_array and 500 array([0, 0, 0, ..., 1, 1, 1, ... , 0, 0, 0]) >>> train(data[mask_array]) # trains with 200~299 >>> predict(data[~mask_array]) # predicts with 0~199, 300~499 回答1: Here's one way: In [1]:

Postgres excludes NULL in WHERE id != int query

我是研究僧i 提交于 2020-02-13 04:36:49
问题 I came up against a strange problem in Postgres yesterday when trying to filter out user ids from a stats table. When we did, for example, user_id != 24 , postgres excluded the rows where user_id is NULL as well. I created the following test code which shows the same results. CREATE TEMPORARY TABLE test1 ( id int DEFAULT NULL ); INSERT INTO test1 (id) VALUES (1), (2), (3), (4), (5), (2), (4), (6), (4), (7), (5), (9), (5), (3), (6), (4), (3), (7), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL)

Postgres excludes NULL in WHERE id != int query

风流意气都作罢 提交于 2020-02-13 04:35:09
问题 I came up against a strange problem in Postgres yesterday when trying to filter out user ids from a stats table. When we did, for example, user_id != 24 , postgres excluded the rows where user_id is NULL as well. I created the following test code which shows the same results. CREATE TEMPORARY TABLE test1 ( id int DEFAULT NULL ); INSERT INTO test1 (id) VALUES (1), (2), (3), (4), (5), (2), (4), (6), (4), (7), (5), (9), (5), (3), (6), (4), (3), (7), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL)