0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

複数のカタログの共通項を高速探索

Last updated at Posted at 2023-07-21

list_A, list_B の共通する部分のインデックスを探すのは、for 文を使うより、以下の方が早い。

both = set(list_A).intersection(list_B)

indices_A = [list_A.index(x) for x in both]
indices_B = [list_B.index(x) for x in both]

これをもとに、2つのtableから共通項を高速に取り出すことができる。

# list_sid_APOGEE  -- データA
# list_sid_table_i -- データB

table_i = Table.read(finelame_i)
    
list_sid_table_i = list(table_i['sid'].data)

both = set(list_sid_table_i).intersection(list_sid_APOGEE)

indices_table_i      = [list_sid_table_i.index(x) for x in both]
#indices_table_APOGEE = [list_sid_APOGEE. index(x) for x in both]

table_i = table_i[indices_table_i]

次は、動くけれど遅いやり方:

# list_sid_APOGEE  -- データA
# list_sid_table_i -- データB

table_i = Table.read(finelame_i)
    
list_sid_table_i = list(table_i['sid'].data)

filter_sid = [ sid in list_sid_APOGEE for sid in (table_i['sid']) ]
table_i = table_i[filter_sid]

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?