Probably there's something wrong with the input values for X and/or T. The function from the question works ok:

import numpy as np
from math import e

def sigmoid(X, T):
  return 1.0 / (1.0 + np.exp(-1.0 * np.dot(X, T)))

X = np.array([[1, 2, 3], [5, 0, 0]])
T = np.array([[1, 2], [1, 1], [4, 4]])

print(X.dot(T))
# Just to see if values are ok
print([1. / (1. + e ** el) for el in [-5, -10, -15, -16]])
print()
print(sigmoid(X, T))

Result:

[[15 16]
 [ 5 10]]

[0.9933071490757153, 0.9999546021312976, 0.999999694097773, 0.9999998874648379]

[[ 0.99999969  0.99999989]
 [ 0.99330715  0.9999546 ]]

Probably it's the dtype of your input arrays. Changing X to:

X = np.array([[1, 2, 3], [5, 0, 0]], dtype=object)

Gives:

Traceback (most recent call last):
  File "/[...]/stackoverflow_sigmoid.py", line 24, in <module>
    print sigmoid(X, T)
  File "/[...]/stackoverflow_sigmoid.py", line 14, in sigmoid
    return 1.0 / (1.0 + np.exp(-1.0 * np.dot(X, T)))
AttributeError: exp
Answer from H.D. on Stack Overflow
🌐
Fast.ai
forums.fast.ai › part 1 (2018)
AttributeError 'float object has no attribute 'cpu' - first model - Part 1 (2018) - fast.ai Course Forums
October 9, 2018 - Followed all the setup steps, including using the fastai template in paperspace. Everything fine until I try to use the first model “Our first model: quick start”. I get: AttributeError: 'float object has no attribute ‘cpu’ No idea why this might be. I’m relatively new to python and ML.
🌐
GitHub
github.com › theislab › scarches › issues › 36
"AttributeError: 'float' object has no attribute 'cpu'" · Issue #36 · theislab/scarches
January 5, 2021 - /PHShome/ik936/anaconda3/envs/scarches3/lib/python3.6/site-packages/scarches/trainers/trvae/trainer.py in on_epoch_end(self) 266 if "loss" in key: 267 self.logs["epoch_" + key].append( --> 268 sum(self.iter_logs[key][:]).cpu().detach().numpy() / len(self.iter_logs[key][:])) 269 270 # Validate Model · AttributeError: 'float' object has no attribute 'cpu' Reactions are currently unavailable ·
Author   ilyakorsunsky
Discussions

if np.isnan(grad_norm.cpu()): AttributeError: 'float' object has no attribute 'cpu'
There was an error while loading. Please reload this page · 运行环境:天池实验室notebook gpu https://tianchi.aliyun.com/ https://dsw-dev.data.aliyun.com/ run: !python synthesizer_train.py mandarin /data/nas/workspace/jupyter/data/SV2TTS/synthesizer More on github.com
🌐 github.com
5
October 19, 2021
python - Numpy AttributeError: 'float' object has no attribute 'exp' - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
python - AttributeError: 'numpy.float64' object has no attribute 'cpu' - Stack Overflow
I am trying to run BERT and train a model using pytorch. I am not sure why I am getting this error after finishing the first Epoch. I am using this code link history = defaultdict(list) best_accura... More on stackoverflow.com
🌐 stackoverflow.com
AttributeError: 'float' object has no attribute 'detach'
I am trying to do this : my_file3 = x_mean[1].detach().cpu().numpy() and it shows me this error : AttributeError: ‘float’ object has no attribute ‘detach’ More on discuss.pytorch.org
🌐 discuss.pytorch.org
0
0
March 11, 2021
🌐
GitHub
github.com › fastai › fastai › issues › 865
'float' object has no attribute '"cpu"' · Issue #865 · fastai/fastai
October 8, 2018 - Describe the bug Run time error for fastai-v0: 'float' object has no attribute '"cpu"' in core.py to_np(v) It seems like this was caused by a recent commit: f62716c I changed the function as follows: def to_np(v): '''returns an np.array ...
Author   james-woo
🌐
GitHub
github.com › babysor › MockingBird › issues › 160
if np.isnan(grad_norm.cpu()): AttributeError: 'float' object has no attribute 'cpu' · Issue #160 · babysor/MockingBird
October 19, 2021 - Traceback (most recent call last): File "synthesizer_train.py", line 35, in train(**vars(args)) File "/data/nas/workspace/jupyter/MockingBird/synthesizer/train.py", line 200, in train if np.isnan(grad_norm.cpu()): AttributeError: 'float' object has no attribute 'cpu' No one assigned ·
Author   lcp580
🌐
Bobby Hadz
bobbyhadz.com › blog › python-attributeerror-float-object-has-no-attribute
AttributeError: 'float' object has no attribute 'X' (Python) | bobbyhadz
The Python "AttributeError: 'float' object has no attribute" occurs when we try to access an attribute that doesn't exist on a floating-point number, e.g.
Find elsewhere
🌐
PyTorch Forums
discuss.pytorch.org › t › attributeerror-float-object-has-no-attribute-detach › 114461
AttributeError: 'float' object has no attribute 'detach' - PyTorch Forums
March 11, 2021 - I am trying to do this : my_file3 = x_mean[1].detach().cpu().numpy() and it shows me this error : AttributeError: ‘float’ object has no attribute ‘detach’
🌐
GitHub
github.com › ranaroussi › yfinance › issues › 1096
AttributeError: 'float' object has no attribute 'upper' · Issue #1096 · ranaroussi/yfinance
October 19, 2022 - Any ideas on the error below? My code works fine on windows locally on my laptop, it basically pulls data for a group of 5000 stocks 1 by 1. When i try to run it onlinus most of the symbols work fi...
Author   gib-uk
🌐
Stack Overflow
stackoverflow.com › questions › 57989774 › attributeerror-numpy-float32-object-has-no-attribute-to-cpu
chainer - AttributeError: 'numpy.float32' object has no attribute 'to_cpu' - Stack Overflow
September 18, 2019 - Would you share the definition of model? It looks model(...) returns a numpy.ndarray object (not chainer.Variable), which causes the error. ... Try to use acc_data = cuda.to_cpu(acc_data).
🌐
GitHub
github.com › bryancatanzaro › copperhead › issues › 9
AttributeError: 'float' object has no attribute '__name__' · Issue #9 · bryancatanzaro/copperhead
February 23, 2013 - I use an array of numpy.float64 tuple values to compute results. However when I run it, copperhead gives me the following trace although python interpreter works perfectly: Trying to read file (" inputs/in_4.txt ") content into a list ... Now computing CPU prices ...
Author   mohdsm81
🌐
Esri Community
community.esri.com › t5 › python-questions › attributeerror-float-object-has-no-attribute › td-p › 39532
Solved: AttributeError: 'float' object has no attribute 's... - Esri Community
December 12, 2021 - I'm hoping someone can tell me whats going on with the below bit of code. I keep getting the error AttributeError: 'float' object has no attribute 'setValue' and I'm not sure how to resolve it. Can someone please explain? NONFLOOD = "GRIDfield" NF1curs = arcpy.UpdateCursor(BuildingGridSe...
🌐
GitHub
github.com › choderalab › espaloma › issues › 130
AttributeError: 'float' object has no attribute 'value_in_unit' (and others) · Issue #130 · choderalab/espaloma
September 26, 2022 - AttributeError: 'float' object has no attribute 'value_in_unit' (and others)#130 · Copy link · mikemhenry · opened · on Sep 26, 2022 · Issue body actions · Right now CI is failing due to the new openff toolkit using a different package for units. The openff-unit package provides a way to support both using openmm.units and openff.units.
Author   mikemhenry
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-fix-attributeerror-object-has-no-attribute
How to fix AttributeError: object has no attribute - GeeksforGeeks
July 23, 2025 - To understand this error, we first have to know how to read the error message effectively. It typically consists of two parts: "AttributeError" and "Object has no attribute." The former indicates the type of error, and the latter suggests that the attribute we are trying to access does not exist for the object.
🌐
Real Python
realpython.com › ref › builtin-exceptions › attributeerror
AttributeError | Python’s Built-in Exceptions – Real Python
Every Python object will raise an AttributeError when you attempt to access a non-existent attribute on it. When you need to implement custom logic, then you can edit .__getattr__() accordingly before raising the error manually: ... >>> class CustomObject: ... def __getattr__(self, name): ... # Write to logs ... raise AttributeError(f"No '{name}' here.") ...
🌐
Fast.ai
forums.fast.ai › intro to machine learning (2018)
Intro to ML (lesson 8): AttributeError: 'float' object has no attribute 'rint' - Intro to Machine Learning (2018) - fast.ai Course Forums
March 4, 2019 - Hi, I’m running the following code under the fastai-cpu: net = nn.Sequential( nn.Linear(28*28, 100), nn.ReLU(), nn.Linear(100, 100), nn.ReLU(), nn.Linear(100, 10), nn.LogSoftmax() ) When I tried the following command: fit(net, md, n_epochs=5, crit=loss, opt=opt, metrics=metrics) I got the following error: AttributeError Traceback (most recent call last) ~/.local/lib/python3.6/site-packages/numpy/core/fromnumeric.py in _wrapfunc(obj, method, *args, **kwds...
Top answer
1 of 9
65

The answer is already provided in the comments by @mattdmo and @tdelaney:

  • NumPy 1.20 (release notes) deprecated numpy.float, numpy.int, and similar aliases, causing them to issue a deprecation warning

  • NumPy 1.24 (release notes) removed these aliases altogether, causing an error when they are used

In many cases you can simply replace the deprecated NumPy types by the equivalent Python built-in type, e.g., numpy.float becomes a "plain" Python float.

For detailed guidelines on how to deal with various deprecated types, have a closer look at the table and guideline in the release notes for 1.20:

...

To give a clear guideline for the vast majority of cases, for the types bool, object, str (and unicode) using the plain version is shorter and clear, and generally a good replacement. For float and complex you can use float64 and complex128 if you wish to be more explicit about the precision.

For np.int a direct replacement with np.int_ or int is also good and will not change behavior, but the precision will continue to depend on the computer and operating system. If you want to be more explicit and review the current use, you have the following alternatives:

  • np.int64 or np.int32 to specify the precision exactly. This ensures that results cannot depend on the computer or operating system.
  • np.int_ or int (the default), but be aware that it depends on the computer and operating system.
  • The C types: np.cint (int), np.int_ (long), np.longlong.
  • np.intp which is 32bit on 32bit machines 64bit on 64bit machines. This can be the best type to use for indexing.

...

If you have dependencies that use the deprecated types, a quick workaround would be to roll back your NumPy version to 1.24 or less (as suggested in some of the other answers), while waiting for the dependency to catch up. Alternatively, you could create a patch yourself and open a pull request, or monkey patch the dependency in your own code.

2 of 9
39

In the 1.24 version:

The deprecation for the aliases np.object, np.bool, np.float, np.complex, np.str, and np.int is expired (introduces NumPy 1.20). Some of these will now give a FutureWarning in addition to raising an error since they will be mapped to the NumPy scalars in the future.

pip install "numpy<1.24" to work around it.

In [1]: import numpy as np

In [2]: np.__version__
Out[2]: '1.23.5'

In [3]: np.float(3)
<ipython-input-3-8262e04d58e1>:1: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  np.float(3)
Out[3]: 3.0