Q. Explain how to create a 2D array in NumPy in Machine Learning.
(Subject Code: 4341603)
Ans:
In Machine Learning, data is usually represented in the form of a 2D array, where:
-> Rows represent data samples
-> Columns represent features
We can create a 2D array in Python using the NumPy library.
Step 1: Import NumPy
import numpy as np
Step 2: Create a 2D array using a list of lists
arr = [Link]([[1, 2, 3], [4, 5, 6]])
This creates a 2D array with 2 rows and 3 columns.
Explanation:
Each inner list [1, 2, 3] and [4, 5, 6] represents a row. NumPy combines them into a 2D array structure.
Conclusion:
Using [Link]() with a list of lists is the simplest and most commonly used method to create a 2D array in
---
What is a Column in a 2D Array?
In a 2D array, data is arranged in rows and columns, like a table.
Example:
arr = [Link]([[1, 2, 3],
[4, 5, 6]])
This array looks like:
1 2 3
4 5 6
- Rows: Horizontal -> [1, 2, 3] and [4, 5, 6]
- Columns: Vertical ->
Column 1: 1, 4
Column 2: 2, 5
Column 3: 3, 6
So, a column is a vertical slice of the array.
Each column represents one feature (variable) in Machine Learning.