0Pricing
Data Science Academy · Lekcja

Zmienianie kształtu i spłaszczanie tablic

Zmieniaj wymiary bez utraty danych.

Zmienianie kształtu i spłaszczanie tablic to bezpłatna lekcja Data Science Academy na CoddyKit. To lekcja 1 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Data Science Academy, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Data Science Academy zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

Same Data, New Shape

An array is just numbers plus a shape. Reshaping rearranges those numbers into new dimensions without copying or changing a single value.

Calling reshape

Use reshape to lay 12 numbers out as a 3 by 4 grid. The total count must stay the same, or NumPy raises an error.

import numpy as np
a = np.arange(12)
b = a.reshape(3, 4)

Rows Times Columns

The new shape only works if the dimensions multiply to the original size. Here 3 times 4 equals 12, so the reshape fits perfectly.

Let NumPy Do the Math

Pass -1 for one dimension and NumPy computes it for you. It is a handy shortcut when you only know one side of the grid.

a = np.arange(12)
b = a.reshape(3, -1)   # becomes 3 x 4

Going to 1D With ravel

Need a flat line of numbers again? ravel collapses any array into a single dimension, reading values row by row.

grid = np.arange(6).reshape(2, 3)
flat = grid.ravel()   # [0 1 2 3 4 5]

flatten Makes a Copy

The flatten method also returns 1D, but always as a fresh copy. Editing the result never touches the original array.

flat = grid.flatten()
flat[0] = 99   # grid is untouched

ravel May Share Memory

Unlike flatten, ravel often returns a view that shares memory with the source. Change the view and the original can change too.

Add a Dimension

A 1D array can grow into a column with reshape. Turning shape (3,) into (3, 1) is common before stacking or matrix math.

v = np.array([1, 2, 3])
col = v.reshape(3, 1)

Transpose Flips Axes

The .T attribute swaps rows and columns. A 2 by 3 array instantly becomes 3 by 2, mirroring the data across its diagonal.

grid = np.arange(6).reshape(2, 3)
turned = grid.T   # shape 3 x 2

Shape Must Stay Consistent

You cannot reshape 10 numbers into a 3 by 4 grid. The element count on both sides must match, so plan dimensions before you reshape.

Why Reshaping Matters

Models and plotting tools expect specific shapes. Reshaping lets one block of numbers serve a vector, a matrix, or an image as needed.

Quick Check

You want a guaranteed independent 1D copy of an array.

Reshape Recap

You reshaped data while keeping its values, used -1 for auto sizing, and learned that flatten copies while ravel may share memory. 🎯

Często zadawane pytania

Czy lekcja „Zmienianie kształtu i spłaszczanie tablic” jest bezpłatna?

Tak — pełny tekst „Zmienianie kształtu i spłaszczanie tablic” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Data Science Academy, przejdź na CoddyKit PRO. Kurs Data Science Academy zawiera 4 lekcji w sumie.

Co nauczysz się w „Zmienianie kształtu i spłaszczanie tablic”?

Zmieniaj wymiary bez utraty danych. Ćwiczysz Data Science Academy z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć Data Science Academy?

Nie wymagamy żadnego doświadczenia. Data Science Academy w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 1 z 4.

Ile czasu zajmuje lekcja „Zmienianie kształtu i spłaszczanie tablic”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji Data Science Academy?

Tak. Każda lekcja Data Science Academy zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Zmienianie kształtu i spłaszczanie tablic
  2. Suma, średnia i sztuczka z osią
  3. Maski logiczne do wyboru danych
  4. Liczby losowe i ziarna
← Powrót do Data Science Academy