#### [SOLVED] Why there are two square brackets required inside numpy array?

I am learning python, and I recently came across a module Numpy. With the help of Numpy, one can convert list to arrays and perform operations much faster. Let's say we create an array with following values :

``````import numpy as np
np_array=array([1,2,3,4,5])
``````

So we need one square bracket if we need to store one list in the form of array. Now if I want to create a 2D array, why it should be defined like this:

``````np_array=array([[1,2,3,4,5],[6,7,8,9,10]])
``````

And not like this:

``````np_array=array([1,2,3,4,5],[6,7,8,9,10])
``````

I apologize if this question is a duplicate, but I couldn't find any answer.

Many Thanks

#### @DeepSpace 2018-03-13 15:48:43

This actually has little to do with `numpy`. You are essentially asking what is the difference between `foo(a, b)` and `foo([a, b])`.

`arbitrary_function([1, 2, 3, 4, 5], [6, 7, 8, 9, 10])` passes two lists as separate arguments to `arbitrary_function` (one argument is `[1, 2, 3, 4, 5]` and the second is `[6, 7, 8, 9, 10]`).

`arbitrary_function([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])` passes a list of lists (`[[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]`) to `arbitrary_function`.

Now, `numpy` creators could have chosen to allow
`arbitrary_function([1, 2, 3, 4, 5], [6, 7, 8, 9, 10])` but it would have made little to no sense to do so.

#### @Ayush Goyal 2018-03-13 15:56:26

Thank you for such a detailed answer. This cleared all the doubts :)

#### @Axeon Thra 2018-03-13 15:48:53

Array function has the following form.

``````array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0)
``````

If you use

``````np_array=array([1,2,3,4,5],[6,7,8,9,10])
``````

The function call will result in passing [1,2,3,4,5] to object and [6,7,8,9,10] to dtype, which wont make any sense.

#### @Ayush Goyal 2018-03-13 15:50:52

That was helpful! Thank you :)

#### @DeepSpace 2018-03-13 15:56:04

One could then ask why `array`'s signature is not `array(*objects, dtype=None, copy=True, order=None, subok=False, ndmin=0)` and the answer would be "because it wouldn't make any sense" and that it would probably go against several conventions (and would also probably complicate `array`'s implementation)

### [SOLVED] What are the advantages of NumPy over regular Python lists?

• 2009-06-14 23:02:14
• Thomas Browne
• 133154 View
• 386 Score
• Tags:   python numpy

### [SOLVED] Suppress Scientific Notation in Numpy When Creating Array From Nested List

• 2012-03-19 20:54:15
• donopj2
• 62380 View
• 106 Score
• Tags:   python numpy

### [SOLVED] Shift elements in a numpy array

• 2015-05-22 14:36:42
• chrisaycock
• 44915 View
• 44 Score
• Tags:   python numpy

### [SOLVED] numpy array specify a default

• 2015-06-23 17:48:14
• py_works
• 561 View
• 2 Score
• Tags:   python numpy