</>
Skip to content
NumPy lessons (14/28)

NumPy — Array Split

Key attributes

import numpy as np

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

print(f"Shape: {arr.shape}")      # (2, 3)
print(f"Size: {arr.size}")        # 6
print(f"Ndim: {arr.ndim}")        # 2
print(f"Dtype: {arr.dtype}")      # int64
print(f"Itemsize: {arr.itemsize}") # 8 bytes

reshape

arr = np.array([1, 2, 3, 4, 5, 6])
reshaped = arr.reshape(2, 3)
print(reshaped)

flatten

arr_2d = np.array([[1, 2], [3, 4]])
flat = arr_2d.flatten()
print(flat)  # [1, 2, 3, 4]

T (transpose)

arr = np.array([[1, 2], [3, 4]])
print(arr.T)

dtype

arr = np.array([1, 2, 3], dtype=np.float32)
print(arr.dtype)  # float32

Mini Practice

  1. Check shape and size
  2. Reshape arrays
  3. Transpose matrices
  4. Work with dtypes

Up Next

Continue with Indexing - Accessing elements.

Related Topics

Frequently Asked Questions about Array Split

What is Array Split in NumPy?

Array Split is a fundamental concept in NumPy. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Array Split?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Array Split.

Why is Array Split important in NumPy?

Array Split is essential for NumPy development. Understanding this concept will help you write better code and solve real-world problems more effectively.