We Are Going To Discuss About **setting an array element with a sequence requested array has an inhomogeneous shape after 1 dimensions The detected shape was (2,)+inhomogeneous part**. So lets Start this Python Article.

## setting an array element with a sequence requested array has an inhomogeneous shape after 1 dimensions The detected shape was (2,)+inhomogeneous part

**How to solve setting an array element with a sequence requested array has an inhomogeneous shape after 1 dimensions The detected shape was (2,)+inhomogeneous part**Here's a simple case that produces your error message:

`In [19]: np.asarray([[1,2,3],[4,5]],float) Traceback (most recent call last): File "<ipython-input-19-72fd80bc7856>", line 1, in <module> np.asarray([[1,2,3],[4,5]],float) File "/usr/local/lib/python3.8/dist-packages/numpy/core/_asarray.py", line 102, in asarray return array(a, dtype, copy=False, order=order) ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.`

If I omit the`float`

, it makes an object dtype array – with warning.`In [20]: np.asarray([[1,2,3],[4,5]]) /usr/local/lib/python3.8/dist-packages/numpy/core/_asarray.py:102: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray. return array(a, dtype, copy=False, order=order) Out[20]: array([list([1, 2, 3]), list([4, 5])], dtype=object)`

**setting an array element with a sequence requested array has an inhomogeneous shape after 1 dimensions The detected shape was (2,)+inhomogeneous part**Here's a simple case that produces your error message:

`In [19]: np.asarray([[1,2,3],[4,5]],float) Traceback (most recent call last): File "<ipython-input-19-72fd80bc7856>", line 1, in <module> np.asarray([[1,2,3],[4,5]],float) File "/usr/local/lib/python3.8/dist-packages/numpy/core/_asarray.py", line 102, in asarray return array(a, dtype, copy=False, order=order) ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.`

If I omit the`float`

, it makes an object dtype array – with warning.`In [20]: np.asarray([[1,2,3],[4,5]]) /usr/local/lib/python3.8/dist-packages/numpy/core/_asarray.py:102: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray. return array(a, dtype, copy=False, order=order) Out[20]: array([list([1, 2, 3]), list([4, 5])], dtype=object)`

## Solution 1

Here’s a simple case that produces your error message:

```
In [19]: np.asarray([[1,2,3],[4,5]],float)
Traceback (most recent call last):
File "<ipython-input-19-72fd80bc7856>", line 1, in <module>
np.asarray([[1,2,3],[4,5]],float)
File "/usr/local/lib/python3.8/dist-packages/numpy/core/_asarray.py", line 102, in asarray
return array(a, dtype, copy=False, order=order)
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
```

If I omit the `float`

, it makes an object dtype array – with warning.

```
In [20]: np.asarray([[1,2,3],[4,5]])
/usr/local/lib/python3.8/dist-packages/numpy/core/_asarray.py:102: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
return array(a, dtype, copy=False, order=order)
Out[20]: array([list([1, 2, 3]), list([4, 5])], dtype=object)
```

Original Author hpaulj Of This Content

## Conclusion

So This is all About **This Tutorial.** Hope This Tutorial Helped You. Thank You.