How to use digitize, python, numpy



Python
library
pip

MeCab

Common
class

pickle

read/readline

numpy
asfarray

digitize

expit

linalg.solve

meshgrid

mgrid

ndmin

pad

poly1d

polyfit

prod

shape

matplotlib
figure

pcolormesh

scatter

pytorch
BCELoss, MSELoss

device

Embedding

TensorDataset, Dataloader

RNN, LSTM
scikit-learn
SVC

GaussianNB

scipy
interpolate
tkinter
postscript

image display

frame, grid

Crop Image

other
linear interpolation

Hysteresis switch

Square/Triangle wave

OpenAI gym
CartPole-v0

By purpose
1 of K Coding


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

Common
class

pickle

read/readline

numpy
asfarray

digitize

expit

linalg.solve

meshgrid

mgrid

ndmin

pad

poly1d

polyfit

prod

shape

matplotlib
figure

pcolormesh

scatter

pytorch
BCELoss, MSELoss

device

Embedding

TensorDataset, Dataloader

RNN, LSTM
scikit-learn
SVC

GaussianNB

scipy
interpolate
tkinter
postscript

image display

frame, grid

Crop Image

other
linear interpolation

Hysteresis switch

Square/Triangle wave

OpenAI gym
CartPole-v0

By purpose
1 of K Coding