NumPy - Creating ArraysWhich of the following is the correct syntax to create a 2D NumPy array with values 1, 2 in the first row and 3, 4 in the second row?Anp.array([[1, 2], [3, 4]])Bnp.array([1, 2, 3, 4])Cnp.array(1, 2, 3, 4)Dnp.array([1, 2], [3, 4])Check Answer
Step-by-Step SolutionSolution:Step 1: Understand 2D array creation syntaxNumPy expects a list of lists for 2D arrays, so nested brackets are needed.Step 2: Identify correct optionOnly np.array([[1, 2], [3, 4]]) uses nested lists correctly: [[1, 2], [3, 4]].Final Answer:np.array([[1, 2], [3, 4]]) -> Option AQuick Check:2D array needs nested lists [OK]Quick Trick: Use double brackets for 2D arrays in np.array [OK]Common Mistakes:Missing nested bracketsPassing multiple arguments instead of one listUsing flat list for 2D array
Master "Creating Arrays" in NumPy9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More NumPy Quizzes Array Operations - Logical operations (and, or, not) - Quiz 6medium Broadcasting - Broadcasting compatibility check - Quiz 12easy Broadcasting - 1D and 2D broadcasting - Quiz 9hard Broadcasting - Why broadcasting matters - Quiz 12easy Creating Arrays - np.arange() for range arrays - Quiz 14medium Creating Arrays - np.eye() for identity matrices - Quiz 3easy Indexing and Slicing - Slicing with start:stop:step - Quiz 7medium NumPy Fundamentals - Array attributes (shape, dtype, ndim, size) - Quiz 14medium NumPy Fundamentals - NumPy and scientific computing ecosystem - Quiz 1easy NumPy Fundamentals - NumPy and scientific computing ecosystem - Quiz 13medium