TypeError: iteration over a 0-d array Python

前端 未结 2 1193
既然无缘
既然无缘 2020-12-19 05:42

I am trying to write a very basic nearest neighbor calculation. I basically want to see what t looks like but I got this type error. When I asked the funciton to return just

2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-19 06:21

    It is possible to load a 0-d numpy array with arr1 = np.load(..., allow_pickle=True). To access the item stored as being a np.array, use:

    arr1.item()
    

    For instance, if the type stored is a dict d1 = {'item1':42, 'item2':np.array(1,3)} we can get the value as such: v1 = arr1.item()['item2'].

    Important: Loading with allow_pickle=True is brings security risks and is not recommended.

提交回复
热议问题