0% found this document useful (0 votes)
4 views2 pages

Creating 2D Arrays in NumPy

In Machine Learning, a 2D array is used to represent data samples and features, with rows for samples and columns for features. A 2D array can be created in Python using the NumPy library with the np.array() function, utilizing a list of lists. Each inner list corresponds to a row, and columns represent vertical slices of the array, with each column indicating a specific feature.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Creating 2D Arrays in NumPy

In Machine Learning, a 2D array is used to represent data samples and features, with rows for samples and columns for features. A 2D array can be created in Python using the NumPy library with the np.array() function, utilizing a list of lists. Each inner list corresponds to a row, and columns represent vertical slices of the array, with each column indicating a specific feature.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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.

You might also like