Eliminate the arr.sort (1) line in the code below,
If i suddenly write print (arr.sort (1)), None will be output.
Please tell me why you should write arr.sort (1).
import numpy as np arr = np.array ([[8, 4, 2], [3, 5, 1]]) arr.sort (1) print (arr)
Answer # 1
arr.sort (1)method has no return value.
arr.sort ()prioritizes memory efficiency and processing speed by performing destructive sorting
As a Python policy, methods that make destructive changes have no return value
Why doesn't list.sort () return a sorted list? -Design and History FAQ — Python 3.7.5 documentation
Answer # 2
The code calls the
sortmethod of the
numpy.ndarrayobject. As you can see from the reference,
Sort an array in-place. Refer to numpy.sort for full documentation.
numpy.ndarray.sort — NumPy v1.17 Manual
and there is no description of the return value. No return value means that in Python, it returns a
In short, it is a "specification". A general trend of Python built-in functions and objects, library functions and methods is that "methods that change objects themselves in-place" returnNot only
None(this is called Command I'm influenced by the idea of the/Query separation principle.
numpyarrays but also built-in
listhas the same specifications, and
list.sortsortedfunction that returns a new sorted
- how to use python 2d array
- python 3x - how to use python class
- python - how to sort a 3d array
- python - how to use numpyinterp
- python - i don't know how to use wait_for_motion () and wait_for_no_motion ()
- python - how to use nltk bleu score
- python - how to use tensorflow placeholder
- how to use python iobytesio
- python - how to use threadpoolexecutor
- php - how to use last_insert_id?
- i want to dynamically change the value of a variable in python and execute it
- website - how do i use bootstrap with wordpress?
- i want to put it in another variable with python for
- python - can i use encoding = "utf-8" in csv file?
- python - filename cannot be assigned to a variable when using a for statement with a shell command in google colaboratory
- how to use c # inheritance
- how to use streaming api in vbnet
- linux - how to use wildcards in the find command
- python - i don't know how to do css select in bs4
- python : "Indicator" function for array elements
- python : Need help finding the index on the Series object s
- python : How to draw a function using matplotlib?
- python : Conversion from numpy to pytorch
- OpenCV + Unity + Python (integrations)
- I want to output csv by combining the character string array and numerical array in Python
- python : Building a nonlinear regression
- Sorting rows of generated matrix (Python)
- python : Help create numpy array
- python : numpy: find maximum and minimum element from a range without using a loop