Data Science · मराठी आवृत्ती · Python basics
P12.6 NumPy 2D Arrays: Rows, Columns आणि Axis
हे का शिकायचं?
Stores × weeks सारखा data table सारखा असतो — rows आणि columns.
हे काय आहे?
2D array म्हणजे lists ची list. arr[row, col] value देतो. axis=0 म्हणजे column नुसार (खाली), axis=1 म्हणजे row नुसार (आडवं).
कसं करायचं?
Step 1. np.array([[…], […]]) बनवा.
Step 2. shape तपासा.
Step 3. sum(axis=0) किंवा sum(axis=1).
उदाहरणं: copy करा आणि चालवा
उदाहरण A: बनवा आणि वाचा
हा code चालवा:
import numpy as np
orders = np.array([[120, 135, 128],
[210, 198, 225]])
print(orders.shape)
print(orders[1, 2])
print(orders[:, 0])
तुम्हाला दिसणारा output:
(2, 3)
225
[120 210]
याचा अर्थ: shape ने rows आणि columns कळले.
उदाहरण B: Store नुसार आणि week नुसार totals
हा code चालवा:
import numpy as np
orders = np.array([[120, 135, 128],
[210, 198, 225]])
print("Per store:", orders.sum(axis=1))
print("Per week:", orders.sum(axis=0))
तुम्हाला दिसणारा output:
Per store: [383 633]
Per week: [330 333 353]
याचा अर्थ: axis=1 ने प्रत्येक store चा आणि axis=0 ने प्रत्येक week चा total मिळाला.