NumPy - Creating ArraysWhich of the following is the correct syntax to create a 1D array of five ones using NumPy?Anp.ones(5)Bnp.ones([5,])Cnp.ones((5,))DAll of the aboveCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand 1D array shapeA 1D array shape can be an integer, a list with one element, or a tuple with one element.Step 2: Check each syntaxnp.ones(5) uses an integer 5, valid for 1D array. np.ones([5,]) uses a list with one element [5,], valid. np.ones((5,)) uses a tuple (5,), also valid.Final Answer:All of the above -> Option DQuick Check:1D array shape can be int, list, or tuple [OK]Quick Trick: 1D shape can be int, list, or tuple with one element [OK]Common Mistakes:Using tuple without comma for single elementConfusing 1D and 2D shapesSyntax errors with missing parentheses
Master "Creating Arrays" in NumPy9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More NumPy Quizzes Array Manipulation - flatten() and ravel() for 1D conversion - Quiz 6medium Array Manipulation - np.newaxis for adding dimensions - Quiz 8hard Array Operations - In-place operations for memory efficiency - Quiz 2easy Array Operations - Universal functions (ufuncs) - Quiz 8hard Broadcasting - Common broadcasting patterns - Quiz 5medium Creating Arrays - np.random.rand() and random arrays - Quiz 10hard Creating Arrays - np.random.rand() and random arrays - Quiz 15hard Creating Arrays - np.zeros() for zero-filled arrays - Quiz 13medium Indexing and Slicing - Boolean indexing - Quiz 9hard NumPy Fundamentals - Array attributes (shape, dtype, ndim, size) - Quiz 4medium