through the use of np.where It can perform more complex operations
np.where ()
score = np.random.randint(40, 100, (10, 5))
score
array([[51, 81, 74, 58, 56],
[94, 79, 51, 92, 94],
[84, 79, 54, 87, 81],
[52, 53, 69, 83, 73],
[42, 68, 67, 50, 55],
[45, 85, 58, 72, 61],
[78, 63, 80, 99, 95],
[66, 45, 51, 89, 48],
[46, 63, 78, 43, 85],
[93, 69, 83, 91, 96]])
temp = score[:4, :4]
# Judgment of the top four students, the first four courses, the grade greater than 60 set to 1, otherwise 0
np.where(temp > 60, 1, 0)
array([[0, 1, 1, 0],
[1, 1, 0, 1],
[1, 1, 0, 1],
[0, 0, 1, 1]])
Compound logic needs combination np.logical_ And and np.logical_ Or use
# determine the first four students, the first four courses, the results of greater than 60 and less than 90 for 1, otherwise 0
np.where(np.logical_and(temp > 60, temp < 90), 1, 0) # greater than 60, less than 90 show 1
array([[0, 1, 1, 0],
[0, 1, 0, 0],
[1, 1, 0, 1],
[0, 0, 1, 1]])
# determine the first four students, the first four courses, the grades in greater than 90 or less than 60 for 1, otherwise 0
np.where(np.logical_or(temp <60, temp > 90), 1, 0) less than 60 greater than 90 show 1
array([[1, 0, 0, 1],
[1, 0, 1, 1],
[0, 0, 1, 0],
[1, 1, 0, 0]])
Read More:
- dtype=np.int error: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`.
- The Usage of Np.random.uniform()
- [Solved] Np.argwhere error: maximum recursion depth exceeded while calling
- [Solved] Operator Not Allowed In Graph Error & Attribute Error Tensor object has no attribute numpy
- RuntimeError: Failed to register operator torchvision::_new_empty_tensor_op. +torch&torchversion Version Matching
- [Solved] NPM install Error: check python checking for Python executable python2 in the PATH
- Invalid python sd, Fatal Python error: init_fs_encoding: failed to get the Python cod [How to Solve]
- How to Solve Python WARNING: Ignoring invalid distribution -ip (e:\python\python_dowmload\lib\site-packages)
- [Solved] opencv-python: recipe for target ‘modules/python3/CMakeFiles/opencv_python3.dir/all‘ failed
- Linux installs Python and upgrades Python
- Python Error: pip install mysql-connector-python failed
- [2021-10-05] Python Error: AttributeError: ‘NoneType‘ object has no attribute ‘append‘
- [Solved] supervisor Error: /usr/local/lib/python2.7/dist-packages/pkg_resources/py2_warn.py:22: UserWarning: Setuptools will stop working on Python 2
- Opencv-python Install is Stuck Error: running setup.py bdist_wheel for opencv-python
- [Solved] Python Error: tensorflow.python.framework.errors_impl.UnknownError: 2 root error(s) found.
- npm install Error: stack Error: Can’t find Python executable “python”
- Pychar can’t connect to Python console, but it can run. Py file, and Anaconda’s command line can run Python command
- Python: RNN principle realized by numpy
- Python+ Pandas + Evaluation of Music Equipment over the years (Notes)
- [Solved] cv2.error: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\……