forked from CURENT/andes
-
Notifications
You must be signed in to change notification settings - Fork 2
/
func.py
38 lines (27 loc) 路 805 Bytes
/
func.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import functools
import operator
from andes.shared import np
def list_flatten(input_list):
"""
Flatten a multi-dimensional list into a flat 1-D list.
"""
if len(input_list) > 0 and isinstance(input_list[0], (list, np.ndarray)):
return functools.reduce(operator.iconcat, input_list, [])
return input_list
def interp_n2(t, x, y):
"""
Interpolation function for N * 2 value arrays.
Parameters
----------
t : float
Point for which the interpolation is calculated
x : 1-d array with two values
x-axis values
y : 2-d array with size N-by-2
Values corresponding to x
Returns
-------
N-by-1 array
interpolated values at `t`
"""
return y[:, 0] + (t - x[0]) * (y[:, 1] - y[:, 0]) / (x[1] - x[0])