Qiita Teams that are logged in
You are not logged in to any team

Community
Service
Qiita JobsQiita ZineQiita Blog
1
Help us understand the problem. What is going on with this article?
@7of9

# Numpy > 2次元データに対して1次元方向に補間をする > interp1d()にてaxis指定で実施する

More than 1 year has passed since last update.

```Python 3.6.8 (default, Aug  7 2019, 17:28:10)
IPython 7.9.0 -- An enhanced Interactive Python. Type '?' for help.
CentOS 6.8
```

### 概要

• WRFという処理で使うOI SSTにおいて、時間補間をしようとしている
• 720x1440の配列が時間方向に9個あり、その状況で時間方向に補間をする
• 要素取出ししながらの補間では処理時間がかかりすぎる

### 方針

```f_out = interp1d(heights, t_in, axis=1)
```

### 実装

```import numpy as np
from scipy.interpolate import interp1d
from time import time

# PEP8 checked

# 1. make test array
print('===DEBUG', time())
xarray = [x * 24 for x in range(-4, 5)]
print(xarray)
target = []
for val in range(9):  # value
olist = np.array([])
for oi in range(720):  # oi: outer index
ilist = []
for ii in range(1440):  # ii: inner index
ilist.append(val)
olist = np.append(olist, np.array(ilist))
target.append(np.array(olist))
target = np.array(target)

# 2. interpolation long the axis of xarray
print('===DEBUG', time())
f_out = interp1d(xarray, target, axis=0)
print(target)
print(len(target))
print(target.dtype)
new_x = np.array([-50, -40, -30])
t_out = f_out(new_x)
print('===DEBUG', time())

print(t_out)

```

### 結果

-50, -40, -30に該当する補間値が求まったようだ。

```===DEBUG 1581303872.2242842
[-96, -72, -48, -24, 0, 24, 48, 72, 96]
===DEBUG 1581303878.1328526
[[0. 0. 0. ... 0. 0. 0.]
[1. 1. 1. ... 1. 1. 1.]
[2. 2. 2. ... 2. 2. 2.]
...
[6. 6. 6. ... 6. 6. 6.]
[7. 7. 7. ... 7. 7. 7.]
[8. 8. 8. ... 8. 8. 8.]]
9
float64
===DEBUG 1581303878.2205226
[[1.91666667 1.91666667 1.91666667 ... 1.91666667 1.91666667 1.91666667]
[2.33333333 2.33333333 2.33333333 ... 2.33333333 2.33333333 2.33333333]
[2.75       2.75       2.75       ... 2.75       2.75       2.75      ]]
```

### 補足

1
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
1. We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
2. you can read useful information later efficiently
By "stocking" the articles you like, you can search right away
セブンオブナインです。Unimatrix 01の第三付属物 9の7という識別番号です。Star trek Voyagerの好きなキャラクターです。まとめ記事は後日タイトルから内容がわからなくなるため、title検索で見つかるよう個々の記事にしてます。いわゆるBorg集合体の有名なセリフから「お前たち（の知識）を吸収する。抵抗は無意味だ」。Thanks in advance.