# AttributeError: 'numpy.ndarray' object has no attribute 'float'

**URL:** <https://discuss.ray.io/t/attributeerror-numpy-ndarray-object-has-no-attribute-float/3558>\
**Category:** RLlib\
**Created:** [September 18, 2021, 3:45pm UTC](https://discuss.ray.io/t/attributeerror-numpy-ndarray-object-has-no-attribute-float/3558 "2021-09-18T15:45:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![deepgravity](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/deepgravity/32/2039_2.png) [@deepgravity](https://discuss.ray.io/u/deepgravity)\
**Post date:** [September 18, 2021, 3:45pm UTC](https://discuss.ray.io/t/attributeerror-numpy-ndarray-object-has-no-attribute-float/3558/1 "2021-09-18T15:45:30Z")

</div>

Hi, I’m using `dqn` for my custom multi-agent `env`. I can test my `evn` with `trainer` and `tune`, both work without any error. After just a few training iterations, I would like to see the agent’s performance with `compute_action`. But I get the following error:  
`AttributeError: 'numpy.ndarray' object has no attribute 'float'`

I ran my code in debugger mode, and I found that the problem comes from `torch_policy.py` line 276.  
`return self._compute_action_helper(input_dict, state_batches, seq_lens, explore, timestep)`

I’m using `torch vision` as the policy. in this line 276, `input_dict` contains the `obs` and `PyTorch` expects to receive it as a Tensor. But, for some reason `RLlib/Ray` stores the `obs tensor` in a `nparray`. As a result, this error rises.

I wonder anyone knows what is happening in the background?

Thanks!

---

<div class="post-metadata">

**Author:** ![arturn](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/arturn/32/2096_2.png) [@arturn](https://discuss.ray.io/u/arturn)\
**Post date:** [September 19, 2021, 7:04pm UTC](https://discuss.ray.io/t/attributeerror-numpy-ndarray-object-has-no-attribute-float/3558/2 "2021-09-19T19:04:26Z")

</div>

Hi @deepgravity

This should not happen. RLlib [converts the complete content of the input\_dict to torch tensors](https://github.com/ray-project/ray/blob/5551cdac19188dd42dd0107202248ae8d75af53c/rllib/utils/torch_ops.py#L86) before computing actions.

Can you breakpoint into this function? … or maybe to [this line](https://github.com/ray-project/ray/blob/master/rllib/policy/torch_policy.py#L262) and see what happens there?

Cheers!

---

<div class="post-metadata">

**Author:** ![deepgravity](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/deepgravity/32/2039_2.png) [@deepgravity](https://discuss.ray.io/u/deepgravity)\
**Post date:** [September 19, 2021, 9:50pm UTC](https://discuss.ray.io/t/attributeerror-numpy-ndarray-object-has-no-attribute-float/3558/3 "2021-09-19T21:50:44Z")

</div>

Hi @arturn  
Many thanks for your reply.

I fixed the error. Actually, it was my fault to send `observation` as a dictionary to the `conpute_action` method. But, the right datatype is a `nparray`.

For those who got into the same problem, here is the solution:

```auto
policy_id = self.config['multiagent']['policy_mapping_fn'](current_agent_name, _)
obs_arr = observation[current_agent_name]
action = self.agent.compute_single_action(obs_arr, policy_id=policy_id)

```

Cheers!
