NumPy - Creating ArraysHow can you create a 4x6 matrix with ones on the diagonal two below the main diagonal using np.eye()?Anp.eye(4, 6, k=-2)Bnp.eye(6, 4, k=2)Cnp.eye(4, 6, k=2)Dnp.eye(6, 4, k=-2)Check Answer
Step-by-Step SolutionSolution:Step 1: Understand matrix shape and diagonal offsetWe want 4 rows and 6 columns, with diagonal shifted two below main diagonal (k=-2).Step 2: Match parametersnp.eye(4, 6, k=-2) matches rows=4, cols=6, diagonal offset -2.Final Answer:np.eye(4, 6, k=-2) -> Option AQuick Check:Rows=4, cols=6, k=-2 for below diagonal [OK]Quick Trick: Rows first, columns second; negative k shifts diagonal down [OK]Common Mistakes:Swapping rows and columnsUsing positive k for below diagonalConfusing matrix shape order
Master "Creating Arrays" in NumPy9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More NumPy Quizzes Aggregation Functions - np.cumsum() for cumulative sum - Quiz 7medium Array Manipulation - np.vstack() and np.hstack() - Quiz 9hard Array Manipulation - np.expand_dims() and np.squeeze() - Quiz 2easy Array Manipulation - np.concatenate() for joining arrays - Quiz 2easy Array Operations - Logical operations (and, or, not) - Quiz 6medium Broadcasting - 1D and 2D broadcasting - Quiz 6medium Broadcasting - Broadcasting errors and debugging - Quiz 8hard Broadcasting - Scalar and array broadcasting - Quiz 5medium NumPy Fundamentals - NumPy array vs Python list performance - Quiz 12easy NumPy Fundamentals - Array attributes (shape, dtype, ndim, size) - Quiz 15hard