Tag Archives: lambda

[Solved] ufunc ‘add‘ did not contain a loop with signature matching types (dtype(‘<U32‘), dtype(‘<U32‘))

Error type:
UFUNC 'Add' did not contain a loop with signature matching types (dtype ('& lt; U32'), dtype ('& lt; U32') - & gt; dtype('<U32')

The ‘Add’ function is a self-defined addition function. The error type is translated as: UFUNC ‘Add’ does not contain a loop with signature matching type. Check the error causes of others. Most of them are due to data type mismatch. The following add function will report this error when x is of type int and y is of type str.

def add(x,y):
    print(type(x))
    print(type(y))
    return x+y

Therefore, I added a function to view the data type in the add function, and found that the data type is:

<class 'numpy.float64'>
<class 'list'>

This confused me. I rechecked my function again

df1["property_grid"]=df1[["wgs84_lon","wgs84_lat"]].apply(lambda x: add( x["wgs84_lon"], ["wgs84_lat"]),axis=1)

It is found that an X is missing. The correct is as follows:

df1["property_grid"]=df1[["wgs84_lon","wgs84_lat"]].apply(lambda x: add( x["wgs84_lon"], x["wgs84_lat"]),axis=1)

Perfect solution~

Lambda set to map duplicate key error solution

  If the same key exists in this method, an error will be reported

Map<String,JKStackRedEx> result = v.stream().collect(Collectors.toMap(a->a.getManuId(),a->a));

The following method can be used to avoid error reporting. The parameter returned by return can specify which value to use to override value1 or Value2

Map<String,JKStackRedEx> result = v.stream().collect(Collectors.toMap(a->a.getManuId(),a->a, (value1, value2) -> {
    return value2;
}));

You can also use multiple attributes to splice keys

Map<String,JKStackRedEx> result = v.stream().collect(Collectors.toMap(a->a.getManuId().concat(a.getStackingNum()),a->a, (value1, value2) -> {
                    return value2;
                }));