TypeError: iteration over a 0-d array Python

TypeError: iteration over a 0-d array Python

TypeError: iteration over a 0-d array Python

The problem is np.array does not take an iterator, you need convert to list first, as below:

n

t = np.array(list(map(lambda v: map(lambda w: distance(v, w, L),n                      x_train.values), x_test.values)))n

n

As per numpy.array documentation, the required parameter must be:

n

n

An array, any object exposing the array interface, an object whosen array method returns an array, or any (nested) sequence.

n

n

Alternatively, use numpy.fromiter and remember to supply dtype, e.g. dtype=float.

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:

n

arr1.item()n

n

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].

n

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

TypeError: iteration over a 0-d array Python

Related posts on Type Error  :

Leave a Reply

Your email address will not be published.