How to use numpy's shape function (python)



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: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

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