Вопрос:

Read info from string

python numpy

35 просмотра

1 ответ

3022 Репутация автора

If I have an input like this:

a = np.array([['31-01-2017 15:02:13.870916 120 0.3'],
              ['31-01-2017 15:02:15.890922 100 0.5'],
            ....])

Is there a way to access the information?

For example, the first is the timestamp, the second is a value (120) and the third another value (0.3)

Автор: George Источник Размещён: 01.02.2017 07:14

Ответы (1)


2 плюса

9480 Репутация автора

Решение

Sure. Split it from right on ' ' with max splits equal to 2.

import numpy as np

a = np.array([['31-01-2017 15:02:13.870916 120 0.3'],
              ['31-01-2017 15:02:15.890922 100 0.5'],
             ])

print a[0][0].rsplit(' ', 2)

Output:

['31-01-2017 15:02:13.870916', '120', '0.3']

List of lists:

l = [['31-01-2017 15:02:13.870916 120 0.3'], ['31-01-2017 15:02:15.890922 100 0.5'] ]
print [a[0].rsplit(' ', 2) for a in l]

Output:

[['31-01-2017 15:02:13.870916', '120', '0.3'], ['31-01-2017 15:02:15.890922', '100', '0.5']]
Автор: MYGz Размещён: 01.02.2017 07:17
Вопросы из категории :
32x32