Tag Archives: Numpy.exp Function Error

Numpy.exp Function Error ‘Float’ object has no attribute ‘exp’

Problem Description:

When python is using a custom sigmoid function, input X as a matrix, there will be a situation where’Float’ object has no attribute’exp’.

def sigmoid(inp):
return 1.0/(1 + np.exp(-inp))

It is found that it is no problem to manually generate the matrix data into this function, and then find it by looking up the numpy.mat function

numpy.mat(data, dtype=None)[source]

Interpret the input as a matrix.

Unlike matrix, asmatrix does not make a copy if the input is already a matrix or an ndarray. Equivalent to matrix(data, copy=False).

Parameters:
data: array_like

Input data.

dtype: data-type

Data-type of the output matrix.

Returns:
mat: matrix

data interpreted as a matrix.

The default dtype is None, so when the matrix is ​​generated, the dtype is added to the type to solve the problem. For example, Xmat = numpy.mat(_x, dtype=float), and then Xmat was brought into the sigmoid function, no problem was found.


AttributeError: 'Float' object has no attribute 'exp'