How to use digitize, python, numpy



Python
library
pip

MeCab

numpy
digitize

mgrid

pad

polyfit

prod

shape

matplotlib
figure

pcolormesh

scatter

pytorch
BCELoss, MSELoss

device

Embedding

TensorDataset, Dataloader

RNN, LSTM
scikit-learn
SVC

scipy
interpolate
tkinter
postscript

image display

frame, grid

other
linear interpolation

OpenAI gym
CartPole-v0


Release date:2024/4/6         

In Japanese


■Explanation of the digitize function

Returns the position of a number in the specified array (this is called bin).

■Concrete example

import numpy as np

a=np.random.uniform(0,100,5) # Create an array with 5 numbers from 0 to 100
print(a)

 ⇒ array([18.20175387, 68.02698607, 43.08681255, 45.76519616, 11.87886015])

b=np.digitize(a, bins=[15, 30, 45, 50, 60])
print(b)

 ⇒ array([1, 5, 2, 3, 0], dtype=int64)


The result is as follows, which returns the position of a in the array defined by bin.









List of related articles



Python
library
pip

MeCab

numpy
digitize

mgrid

pad

polyfit

prod

shape

matplotlib
figure

pcolormesh

scatter

pytorch
BCELoss, MSELoss

device

Embedding

TensorDataset, Dataloader

RNN, LSTM
scikit-learn
SVC

scipy
interpolate
tkinter
postscript

image display

frame, grid

other
linear interpolation

OpenAI gym
CartPole-v0