How to use numpy's shape function (python)



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:2022/12/17         

In Japanese


■Description of the shape function

Returns the shape of the array. A similar function is reshape, which is a function that changes the shape of an array.

■Specific example using shape function

The following is a mandatory description when using numpy.

import numpy as np


example①

a=np.array([1,2,3,4,5,6,7,8,9,10,11,12])
a.shape

⇒ (12,)


example②

a=np.array([[1,2,3],[4,5,6]])
a.shape

⇒ (2, 3)


When extracting each value separately, it is as follows.

b=a.shape[0]
b

⇒ 2

b , c =a.shape
b

⇒ 2

c

⇒ 3










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