In Numpy 1.21.5, this form of sort is allowed:

```
a = np.sort(a, axis=None)
```

but an equivalent in-place version is not:

```
a.sort(axis=None)
```

`axis`

has to have `int`

type in this case. Is there a reason for this?

In Numpy 1.21.5, this form of sort is allowed:

```
a = np.sort(a, axis=None)
```

but an equivalent in-place version is not:

```
a.sort(axis=None)
```

`axis`

has to have `int`

type in this case. Is there a reason for this?

`numpy.sort(array)`

returns a sorted copy of the array, so it is easy to flatten it with `axis=None`

.

`array.sort`

operates in-place. As far as I know, there is no in-place version of flatten.

It seems `a.shape=(a.size,)`

can flatten in-place, and then `a.sort()`

can be used:

```
>>> import numpy
>>> a = numpy.array([[1,20,3],[4,15,6]])
>>> numpy.sort(a, axis=None)
array([ 1, 3, 4, 6, 15, 20])
>>> numpy.sort(a)
array([[ 1, 3, 20],
[ 4, 6, 15]])
>>> a.flatten()
array([ 1, 20, 3, 4, 15, 6])
>>> a
array([[ 1, 20, 3],
[ 4, 15, 6]])
>>> a.shape=(a.size,)
>>> a
array([ 1, 20, 3, 4, 15, 6])
>>> a.sort()
>>> a
array([ 1, 3, 4, 6, 15, 20])
```

2 Likes