Two dimensional lists

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gonzlobo

    #1

    Two dimensional lists

    I might get an answer since I didn't call them arrays. :^)

    Ok, I have 2 lists that I need to process individually, then merge
    them into a 2x list and fill with data.

    arinc429 = ['ab', '2b', '0b', '21', 'c1', '61', '11', 'db', '9b', '5b', 'eb',
    '6b', '1b', '6e', '3e']
    iPIDs = [300, 301, 320, 321]

    merged[arinc429, iPIDs]

    # PID & a429 are defined elsewhere

    a_idx = iPIDs.index[PID]
    p_idx = [arinc429.index[a429]

    # shouldn't I be able to fill the lists simply by pointing to a location?

    matrix[a_idx, p_idx] = 0x219 # and so on?

    tia
  • Peter Otten

    #2
    Re: Two dimensional lists

    gonzlobo wrote:
    I might get an answer since I didn't call them arrays. :^)
    >
    Ok, I have 2 lists that I need to process individually, then merge
    them into a 2x list and fill with data.
    >
    arinc429 = ['ab', '2b', '0b', '21', 'c1', '61', '11', 'db', '9b', '5b',
    'eb',
    '6b', '1b', '6e', '3e']
    iPIDs = [300, 301, 320, 321]
    >
    merged[arinc429, iPIDs]
    >
    # PID & a429 are defined elsewhere
    >
    a_idx = iPIDs.index[PID]
    p_idx = [arinc429.index[a429]
    >
    # shouldn't I be able to fill the lists simply by pointing to a location?
    >
    matrix[a_idx, p_idx] = 0x219 # and so on?
    The simplest approach is to go with a dictionary:
    >>matrix = {}
    >>arinc = ['ab', '2b', '0b']
    >>pids = [300, 321]
    >>for x in arinc:
    .... for y in pids:
    .... matrix[x, y] = y + int(x, 16) # replace with your actual data
    ....
    >>matrix
    {('ab', 300): 471, ('2b', 300): 343, ('ab', 321): 492, ('0b', 321): 332,
    ('2b', 321): 364, ('0b', 300): 311}

    Get one entry:
    >>matrix["2b", 321]
    364

    Get all items along an axis:
    >>[matrix[x, 300] for x in arinc]
    [471, 343, 311]

    Peter

    Comment

    Working...