Understanding dtype in NumPy array in Python

54 Views Asked by At

I have the following array x:

x = np.array([[ 0.        ,  1.        ,  0.47351264,  2.        ],
       [ 2.        ,  3.        ,  0.65425345,  2.        ],
       [20.        , 21.        ,  0.71297456,  2.        ],
       [22.        , 23.        ,  0.6863126 ,  2.        ],
       [24.        , 25.        ,  0.67509844,  2.        ],
       [26.        , 27.        ,  0.68440122,  2.        ],
       [28.        , 29.        ,  0.68737942,  2.        ],
       [30.        , 31.        ,  0.71718599,  2.        ],
       [32.        , 33.        ,  0.73359071,  2.        ],
       [34.        , 35.        ,  0.6795543 ,  2.        ],
       [ 4.        ,  5.        ,  0.64574043,  2.        ],
       [ 6.        ,  7.        ,  0.63806522,  2.        ],
       [ 8.        ,  9.        ,  0.69928704,  2.        ],
       [10.        , 11.        ,  0.6190996 ,  2.        ],
       [12.        , 13.        ,  0.68331497,  2.        ],
       [14.        , 15.        ,  0.65097253,  2.        ],
       [16.        , 17.        ,  0.6896147 ,  2.        ],
       [18.        , 19.        ,  0.61292212,  2.        ],
       [37.        , 38.        ,  0.58519669,  4.        ],
       [47.        , 48.        ,  0.65853573,  4.        ],
       [49.        , 50.        ,  0.63965727,  4.        ],
       [51.        , 52.        ,  0.64220952,  4.        ],
       [53.        , 54.        ,  0.65616207,  4.        ],
       [39.        , 40.        ,  0.70860266,  4.        ],
       [41.        , 42.        ,  0.68387971,  4.        ],
       [43.        , 44.        ,  0.69205266,  4.        ],
       [45.        , 46.        ,  0.73869603,  4.        ],
       [55.        , 56.        ,  0.64534955,  8.        ],
       [57.        , 58.        ,  0.65458359,  8.        ],
       [59.        , 60.        ,  0.70113174,  8.        ],
       [61.        , 62.        ,  0.68490694,  8.        ],
       [63.        , 36.        ,  0.66786758,  5.        ],
       [64.        , 65.        ,  0.67181672, 16.        ],
       [66.        , 67.        ,  0.68897615, 16.        ],
       [69.        , 70.        ,  0.68773403, 32.        ],
       [71.        , 68.        ,  0.6894432 , 37.        ]])

And I tried to execute below: np.array(map(tuple,x),dtype=[('i0',int),('i1',int), ('dist',float),('num',int)]) I am not entirely sure what is the above code trying to achieve. Can someone explain? And I got the following error when I tried to execute the code:

*** TypeError: int() argument must be a string, a bytes-like object or a real number, not 'map'
0

There are 0 best solutions below