1

How would I label the columns in this array. I want to label the left column input and the right column output.

I would also like to split the columns into separate arrays if that is possible ?

                     ([[[ 100000.,     233.],
                        [ 100010.,     299.],
                        [ 100020.,     253.],

                        [ 199980.,     243.],
                        [ 200000.,     247.]],

                       [[ 100000.,     295.],
                        [ 100010.,     294.],
                        [ 100020.,     317.],

                        [ 199980.,     307.],
                        [ 199990.,     321.],
                        [ 200000.,     308.]],

                       [[ 100000.,     338.],
                        [ 100010.,     362.],
                        [ 100020.,     337.],

                        [ 199980.,     334.],
                        [ 199990.,     317.],
                        [ 200000.,     326.]]])

2 Answers 2

1

array[0,:,0] gives you the "input" column, array[0,:,1] the "output". (see numpy slicing). As for labelling the columns, that is usually where you should consider using a dict.

Sign up to request clarification or add additional context in comments.

Comments

1

1. Convert the array to structured array using numpy.core.records.fromarrays:

>>> import numpy as np
>>>
>>> a = np.array(
...   [[[ 100000.,     233.],
...     [ 100010.,     299.],
...     [ 100020.,     253.],
...     [ 199980.,     243.],
...     [ 200000.,     247.]],
...    [[ 100000.,     295.],
...     [ 100010.,     294.],
...     [ 100020.,     317.],
...     [ 199990.,     321.],
...     [ 200000.,     308.]],
...    [[ 100000.,     338.],
...     [ 100010.,     362.],
...     [ 100020.,     337.],
...     [ 199990.,     317.],
...     [ 200000.,     326.]]]
... )
>>> b = np.core.records.fromarrays(
...     a.reshape(-1, 2).T, names='input,output'
... ).reshape(a.shape[:-1])
>>> b[0][0]['input']
100000.0
>>> b[0][0]['output']
233.0

2. Using slicing:

>>> a[..., 0]
array([[ 100000.,  100010.,  100020.,  199980.,  200000.],
       [ 100000.,  100010.,  100020.,  199990.,  200000.],
       [ 100000.,  100010.,  100020.,  199990.,  200000.]])
>>> a[..., 1]
array([[ 233.,  299.,  253.,  243.,  247.],
       [ 295.,  294.,  317.,  321.,  308.],
       [ 338.,  362.,  337.,  317.,  326.]])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.