NumPy — Array Sort
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
- Check shape and size
- Reshape arrays
- Transpose matrices
- Work with dtypes
Up Next
Continue with Indexing - Accessing elements.
Related Topics
Frequently Asked Questions about Array Sort
What is Array Sort in NumPy?
Array Sort 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 Sort?
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 Sort.
Why is Array Sort important in NumPy?
Array Sort is essential for NumPy development. Understanding this concept will help you write better code and solve real-world problems more effectively.