np.array() do when given a Python list?np.array() converts a Python list into a NumPy array, which is a grid of values all of the same type. This allows for fast math and data operations.
Pass a list of lists to np.array(). Each inner list becomes a row in the 2D array.
arr = np.array([[1, 2], [3, 4]])
A Python list can hold different data types and is slower for math. A NumPy array has one data type and is optimized for fast math and memory use.
np.array() handle lists with mixed data types? What happens?Yes, but NumPy will convert all elements to a common data type, usually upcasting to a type that can hold all values (like strings if mixed types). This can affect performance.
Use the .shape attribute to see the dimensions (rows, columns) of the array.
arr = np.array([[1, 2], [3, 4]]) print(arr.shape) # Output: (2, 2)
np.array([1, 2, 3]) return?np.array() converts the list into a NumPy array, not a list or tuple.
Passing a list of lists creates a 2D array.
.shape gives the dimensions of the array.
np.array() do?NumPy converts all elements to a single common type.
NumPy arrays are optimized for fast math and use less memory.