How to select elements row-wise from a NumPy array?

后端 未结 2 1826
一向
一向 2021-02-05 15:05

I have an array like this numpy array

dd= [[foo 0.567 0.611]
     [bar 0.469 0.479]
     [noo 0.220 0.269]
     [tar 0.480 0.508]
     [boo 0.324 0.324]]
         


        
2条回答
  •  攒了一身酷
    2021-02-05 15:45

    First, the vector of first elements is

    dv = dd[:,0]
    

    (python is 0-indexed)

    Second, to walk the array (and store in a dict, for example) you write:

    dc = {}
    ind = 0 # this corresponds to the column with the names
    for row in dd:
        dc[row[ind]] = row[1:]
    

提交回复
热议问题