Replace values of a numpy array by values from another numpy array

后端 未结 4 1043
隐瞒了意图╮
隐瞒了意图╮ 2020-12-18 09:26

i have a 1000 * 1000 numpy array with 1 million values which was created as follows :

>>import numpy as np
>>data = np.loadtxt(\'space_data.txt\         


        
4条回答
  •  Happy的楠姐
    2020-12-18 09:49

    import numpy as np
    
    data = np.array([[ 13.,  15.,  15.],
       [ 14.,  13.,  14. ],
       [ 16.,  13.,  13. ]])
    
    key = [[ 10.,   'S'],
       [ 11.,   'S'],
       [ 12.,   'S'],
       [ 13.,   'M'],
       [ 14.,   'L'],
       [ 15.,   'S'],
       [ 16.,   'S']]
    
    data2 = np.zeros(data.shape, dtype=str)
    
    for k in key:
        data2[data == k[0]] = k[1]
    

提交回复
热议问题