A story that I was addicted to at np.where

Introduction

Since I couldn't output the index extraction of np.where during image processing at all. I understood it while referring to the sample code of here ... So it's a memorandum! If you understand how to read this, you can experience aha! ?? ??

Output of np.where! !! ??

Reference sample code and output. This time the 3rd floor tensor ($ Width \ times Height \ times Channels = 2 \ times 3 \ times 4 $) It is.

a_3d = np.arange(24).reshape(2, 3, 4)
print(a_3d)
# output
# [[[ 0  1  2  3]
#   [ 4  5  6  7]
#   [ 8  9 10 11]]
# 
#  [[12 13 14 15]
#   [16 17 18 19]
#   [20 21 22 23]]]

print(np.where(a_3d < 5))
# output
# (array([0, 0, 0, 0, 0]), array([0, 0, 0, 0, 1]), array([0, 1, 2, 3, 0]))

Here is the output of `np.where (a_3d <5)` Widtharray([0, 0, 0, 0, 0]) Heightarray([0, 0, 0, 0, 1]) Channelsarray([0, 1, 2, 3, 0]) See it as a list of WidthW HeightH ChannelsC To access the elements of the 3rd floor tensor

a_3d[W[0]][H[0]][C[0]] = 0 
a_3d[W[1]][H[1]][C[1]] = 1 
a_3d[W[2]][H[2]][C[2]] = 2 
a_3d[W[3]][H[3]][C[3]] = 3 
a_3d[W[4]][H[4]][C[4]] = 4 

It becomes. Now you can finally read the output of ``` np.where (a_3d <5)` ``!

at the end

At first, the array was just returned, so what is this? I was wondering When you can see the shapes of rows, columns, and depths, they change to meaningful numbers. Aha experience is good ~

Recommended Posts

A story that I was addicted to at np.where
A story that I was addicted to calling Lambda from AWS Lambda.
A story that I was addicted to when I made SFTP communication with python
A story I was addicted to when inserting from Python to a PostgreSQL table
A story I was addicted to trying to install LightFM on Amazon Linux
A story I was addicted to trying to get a video url with tweepy
The story of IPv6 address that I want to keep at a minimum
A story addicted to Azure Pipelines
I was addicted to multiprocessing + psycopg2
A story that I wondered if it stopped working at mglearn.plots.plot_nmf_faces and was an error?
I was addicted to pip install mysqlclient
A note I was addicted to when making a beep on Linux
Note that I was addicted to sklearn's missing value interpolation (Imputer)
A story that was struggling to loop processing 3 million ID data
What I was addicted to Python autorun
The story I was addicted to when I specified nil as a function argument in Go
I was addicted to creating a Python venv environment with VS Code
I was addicted to trying Cython with PyCharm, so make a note
[Introduction to json] No, I was addicted to it. .. .. ♬
A note I was addicted to when running Python with Visual Studio Code
I set up TensowFlow and was addicted to it, so make a note
A story that Seaborn was easy, convenient and impressed
I was addicted to scraping with Selenium (+ Python) in 2020
A story that was terrible if SELinux was properly disabled
I was addicted to trying logging.getLogger in Flask 1.1.x
What I was addicted to when using Python tornado
I was soberly addicted to calling awscli from a Python 2.7 script registered in crontab
A story that was convenient when I tried using the python ip address module
Note that I was addicted to npm script not passing in the verification environment
A story that stumbled when I made a chatbot with Transformer
[IOS] GIF animation with Pythonista3. I was addicted to it.
A word that I was interested in as a programming beginner
What I was addicted to when migrating Processing users to Python
[Fixed] I was addicted to alphanumeric judgment of Python strings
I made a script to say hello at my Koshien
[Python] A story that seemed to fall into a rounding trap
When I tried to install PIL and matplotlib in a virtualenv environment, I was addicted to it.
I was so mushy that I wanted to have a national plane heal me. I have no regrets.
What I was addicted to when dealing with huge files in a Linux 32bit environment
Memo (March 2020) that I was addicted to when installing Arch Linux on MacBook Air 11'Early 2015
I tried to build a service that sells machine-learned data at explosive speed with Docker
I tried to create a server environment that runs on Windows 10
The story that the version of python 3.7.7 was not adapted to Heroku
I tried to make a system that fetches only deleted tweets
A story that I fixed when I got Lambda logs from Cloudwatch Logs
A story that struggled to handle the Python package of PocketSphinx
What I was addicted to when introducing ALE to Vim for Python
What I was addicted to with json.dumps in Python base64 encoding
[Python] A memo that I tried to get started with asyncio
Qiskit: I want to create a circuit that creates arbitrary states! !!
A story that is a little addicted to the authority of the directory specified by expdp (for beginners)
The story that the guard was confined when the laboratory was converted to IoT
A story that didn't work when I tried to log in with the Python requests module
I was addicted to confusing class variables and instance variables in Python
I made a library that adds docstring to a Python stub file.
[Python] When I tried to make a decompression tool with a zip file I just knew, I was addicted to sys.exit ()
I started to work at different times, so I made a bot that tells me the time to leave
[Fabric] I was addicted to using boolean as an argument, so make a note of the countermeasures.
Two things I was addicted to building Django + Apache + Nginx on Windows
I changed my job to a machine learning engineer at AtCoder Jobs
[Python] I made a decorator that doesn't seem to have any use.