Как создать np.sin () с интервалом даты и времени? - PullRequest
0 голосов
/ 08 мая 2020

Как создать np.sin() с интервалом даты и времени?

np.arange(0, 100, 0.1): Не возвращать ошибку при создании массива

start = pd.Timestamp('2015-07-01')
end = pd.Timestamp('2015-08-01')
t = np.linspace(start.value, end.value, 100)
time = pd.to_datetime(t)

#time = np.arange(0, 100, 0.1)
sin = np.sin(time) + np.random.normal(scale=0.5, size=len(time))

Ошибка:

    sin = np.sin(time) + np.random.normal(scale=0.5, size=len(time))
TypeError: ufunc 'sin' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

Время печати:

np_resource = np.dtype ([("ресурс", np.ubyte, 1)]) DatetimeIndex ([
'2015-07-01 00:00:00', ' 2015-07-01 07: 30: 54.545454592 ',' 2015-07-01 15: 01: 49.090909184 ',' 2015-07-01 22: 32: 43.636363520 ',' 2015-07-02 06: 03: 38.181818112 ' , ....

1 Ответ

2 голосов
/ 08 мая 2020

Если вы создаете таймсерии на основе времени, время должно что-то значить, поэтому вы можете преобразовать его в радианы, а затем применить функцию sin, я бы предложил подход, основанный на разнице во времени в секундах:

start = pd.Timestamp('2015-07-01')
end = pd.Timestamp('2015-08-01')
t = np.linspace(start.value, end.value, 100)
time = pd.to_datetime(t)

np.random.seed(0)
t = np.sin(np.radians((time - time.min()).seconds)) + \
    np.random.normal(scale=0.5, size=len(time))

График будет:

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...