0% found this document useful (0 votes)
4 views

Python Nn

The document provides a comprehensive list of interview questions related to NumPy arrays, covering topics such as basic indexing, advanced indexing, boolean masking, modification, broadcasting, and conceptual understanding. Each section includes specific questions with example answers to test the reader's knowledge and skills with NumPy. Additionally, it outlines common built-in functions for various Python data types and highlights the differences between mutable and immutable types.

Uploaded by

shreeshas06
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Python Nn

The document provides a comprehensive list of interview questions related to NumPy arrays, covering topics such as basic indexing, advanced indexing, boolean masking, modification, broadcasting, and conceptual understanding. Each section includes specific questions with example answers to test the reader's knowledge and skills with NumPy. Additionally, it outlines common built-in functions for various Python data types and highlights the differences between mutable and immutable types.

Uploaded by

shreeshas06
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Love this question.

Based on all the indexing, slicing, masking, and


modification tasks you’ve done so far, here are possible interview
questions (ranging from beginner to tricky) that test your conceptual
understanding of NumPy arrays:

🔹 Basic Indexing & Slicing

1. How do you access a specific element in a 2D NumPy array?

Arr[row, col]

2. How would you retrieve a slice of the first 3 elements in a 1D


array?

Arr[0:3]

3. How do you reverse a NumPy array using slicing?

Arr[::-1]

4. How do you extract every 2nd element from a 1D array?

Arr[0::2]

5. How do you get the last N elements of a NumPy array?

Arr[-N:]

🔹 Advanced Indexing

6. How can you access multiple non-consecutive elements by


index in NumPy?
(e.g., positions 1, 3, 4 from an array)

Index= [1,3,4]

Arr[index]

7. How would you retrieve elements at positions (0,1), (1,2),


and (2,0) from a 2D array?

Arr[0,1],arr[1,2] arr[2,0] ?? wromg

Correct: arr[[0,1,2],[1,2,0]]

8. How do you replace only elements at odd rows and odd


columns in a 2D array?

Arr[1::2, 1::2] = replacement


🔹 Boolean Masking

9. How do you get all elements greater than a certain value in


an array?

arr[(arr > value)]

10. How do you replace all negative values in an array with


their absolute values?

arr[(arr < 0)] *= -1

11. How do you extract only even numbers from an array?

arr[::2]* =2

12. How do you conditionally modify elements (e.g., set all


elements > 10 to 0)?

arr[(arr > 10)] = 0

🔹 Modification & Broadcasting

13. How would you replace an entire column or row in a 2D


array?

To replace col

Arr[:,[0,2]] replaces 0th and 2nd col

Arr[[0,4],:] 2nd and 4th row

14. How do you double the values at even indices in a 1D


array?

Arr[(arr %2 == 0)] *= 2

15. How can you replace the first and last column in a 2D
array with 0s?

Arr[:,[0,-1]] =0

16. How do you replace elements divisible by 3 with a


specific value?

arr[(arr %3 ==0)] = specific value

17. Can you assign a string value like 'Divisible by 7' in a


numerical array? What changes are needed in the dtype?
While creating np.array use

Arr= np.array([1,2,3,4], dtype=object)

Then arr[(arr %7 == 0)] = ‘divisble by 7’

🔹 Trickier/Conceptual

18. What’s the difference between arr[::2] and arr[1::2]?

First give even nos 2nd gives odd numbers

19. What does dtype=object do, and when would you use
it?

Allows any datatype to b stored in np array

20. Explain the behavior when you try to modify part of an


array using a condition — does it change the original array
or a copy?

It changes the orginal

21. What's the difference between arr[0::3] and arr[:, [0,


3]]?

First : starts from 0 index and returns every 3rd index value,

Second: return 0th and 3rd col

22. What does NumPy broadcasting mean? How does it


work in assignment or arithmetic operations?

IDK

🔹 Bonus Conceptual

23. How is NumPy indexing different from standard Python


list indexing?

Numpy indexing is faster ?? idk what else is special

Ans :  Can use boolean masks, array-based indexing

 More powerful slicing

 Supports broadcasting

 Doesn’t throw IndexError as easily on slicing


24. Can you use a boolean mask to replace elements in an
array? Show how.

Mask = condition

Then use arr[mask]

25. Why does trying to assign a string to a numeric array


sometimes fail? What is the fix? Cos arrays only take int
value to accept string use dtype= object

Wanna go through mock answers or try solving 5 random ones like a


rapid-fire round? 😎

📚 Python Data Types & Their Built-in Functions

Data Type Common Built-in Functions / Methods

int, float, abs(), round(), pow(), divmod(), complex(), int(), float(),


complex type(), isinstance()

len(), lower(), upper(), capitalize(), title(), strip(), replace(),


str split(), find(), startswith(), endswith(), join(), isalpha(),
isdigit(), islower(), isupper(), count()

len(), append(), extend(), insert(), remove(), pop(), clear(),


list
index(), count(), sort(), reverse(), copy()

len(), count(), index(), type(), isinstance() (only 2 methods:


tuple
count() and index())

range len(), list(), tuple(), type(), used in loops

add(), update(), remove(), discard(), pop(), clear(), union(),


set
intersection(), difference(), issubset(), issuperset(), copy()

union(), intersection(), difference(), issubset(), issuperset(),


frozenset
copy() (immutable version, so no add() or remove())

len(), keys(), values(), items(), get(), update(), pop(),


dict
popitem(), clear(), copy(), setdefault()

bool int(), str(), bool(), can be used in conditions (if, while)


Data Type Common Built-in Functions / Methods

len(), decode(), find(), count(), replace(), split(), join(),


bytes
startswith(), endswith()

len(), append(), extend(), insert(), remove(), pop(),


bytearray
reverse(), decode()

memoryvie
len(), tolist(), tobytes(), slicing operations
w

NoneType
is None (used mainly in comparisons, no methods directly)
(None)

🎯 Important:

 len(), type(), and isinstance() work on almost everything.

 Some types are immutable (string, tuple, frozenset, bytes) — so no


add, remove, modify methods.

✨ Visual Quick Notes:

Mutable? Data Types

✅ Mutable list, set, dict, bytearray

int, float, complex, str, tuple,


❌ Immutable
frozenset, bytes

You might also like