Indexing, slicing, iterating, shape manipulation, and stacking Flashcards

1
Q

What is slicing in multi-dimensional arrays?

A

Slicing allows you to access specific rows, columns, or subarrays. For example, b[0:5, 1] accesses rows from index 0 to index 4, in the second column.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why can’t you reshape a 1D array into a 3x3 array?

A

You cannot reshape if the total number of elements doesn’t match. A 3x3 array requires 9 elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What happens when using -1 in reshape?

A

Using -1 allows NumPy to automatically calculate the missing dimension based on the total number of elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is iterating in programming?

A

Iterating means going through each element of a collection (like an array) one at a time, often using loops.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can you access a specific element in a 2D array?

A

Use indexing with two indices, e.g., array[row_index, column_index].

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does b[:, 1] do?

A

It selects all rows in the second column of the array b.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How can you flatten a multi-dimensional array?

A

Use the ravel() method to convert a multi-dimensional array into a 1D array. It returns a flattened view of the array without altering the original data structure, allowing for easy manipulation and analysis of the elements in a single line.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does the reshape function do?

A

The reshape function changes the shape of an array without altering its data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does the T attribute do for arrays?

A

The T attribute transposes the array, swapping rows and columns.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly