Forma, tamanho e dtype
Leia a anatomia de uma matriz.
Forma, tamanho e dtype é uma aula grátis de Data Science Academy no CoddyKit. Esta é a aula 2 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Data Science Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Data Science Academy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
Read the Array's Anatomy
Every array carries metadata about itself. Three labels tell you almost everything: its shape, its size, and its dtype. Let's read each one. 🔍
Shape: Rows and Columns
The shape is a tuple of dimension lengths. A 3-by-4 grid reports (3, 4): three rows down, four columns across.
a = np.zeros((3, 4))
a.shape # (3, 4)Shape Tells You the Layout
Shape is your first sanity check. If a model expects (100, 5) and you hand it (5, 100), the shape mismatch is where bugs hide.
ndim: How Many Dimensions
The ndim attribute counts dimensions. A flat row is 1, a table is 2, a stack of tables is 3. It is just the length of the shape.
a.ndim # 2Size: Total Element Count
The size is the total number of elements, the product of every shape value. A (3, 4) array has a size of 12.
a.size # 12dtype: The One Shared Type
The dtype names the single type all elements share, like int64 or float64. It controls both precision and memory use.
np.array([1, 2, 3]).dtype # int64Choose Your dtype on Purpose
You can set the type yourself with the dtype argument. Use a smaller type like int32 to save memory on huge arrays.
np.array([1, 2, 3], dtype='int32')dtype Affects Precision
float32 holds fewer decimals than float64. Tiny rounding gaps add up, so pick the type your numbers actually need.
Convert With astype
Already have an array? astype returns a copy in a new type, handy for turning floats into clean integers.
f = np.array([1.0, 2.0])
f.astype('int64')itemsize: Bytes Per Element
The itemsize tells you bytes per element. Multiply it by size to estimate the array's total memory footprint.
a.itemsize # 8 for float64Inspect Before You Compute
Checking shape and dtype first saves hours. They reveal mismatched data and wrong types before a calculation quietly goes wrong. ✅
Quick Check
Let's test your read of an array's shape.
Recap
You can now read an array at a glance: shape for layout, ndim and size for counts, and dtype for the shared type. These four checks catch most bugs early. 🎉
Perguntas Frequentes
A aula “Forma, tamanho e dtype” é grátis?
Sim — o texto completo de “Forma, tamanho e dtype” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Data Science Academy, atualize para CoddyKit PRO. O curso de Data Science Academy inclui 4 aulas no total.
O que vou aprender em “Forma, tamanho e dtype”?
Leia a anatomia de uma matriz. Você pratica Data Science Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Data Science Academy?
Nenhuma experiência prévia é necessária. Data Science Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 2 de 4.
Quanto tempo leva a aula “Forma, tamanho e dtype”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Data Science Academy?
Sim. Cada aula de Data Science Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- De uma lista Python a ndarray
- Forma, tamanho e dtype
- Matemática vetorizada sem laços
- Indexação e fatiamento de matrizes