2018-03-13 15:45:10 8 Comments

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

### Related Questions

#### Sponsored Content

#### 5 Answered Questions

### [SOLVED] Use numpy array in shared memory for multiprocessing

**2011-10-25 19:34:31****Ian Langmore****38888**View**68**Score**5**Answer- Tags: python numpy multiprocessing shared

#### 5 Answered Questions

### [SOLVED] Converting a 3D List to a 3D NumPy array

**2016-10-27 16:35:13****Ziyad Edher****2621**View**4**Score**5**Answer- Tags: python list python-3.x numpy

#### 4 Answered Questions

#### 6 Answered Questions

#### 2 Answered Questions

### [SOLVED] Using numpy arrays of sympy numbers

**2016-12-08 12:50:02****D1X****296**View**2**Score**2**Answer- Tags: python python-3.x numpy sympy

#### 4 Answered Questions

### Easy way of printing two numpy arrays with each element in a different line?

**2016-11-13 18:23:15****Nister****62**View**0**Score**4**Answer- Tags: arrays python-3.x numpy

#### 2 Answered Questions

#### 3 Answered Questions

### [SOLVED] Removing duplicates from a list of numPy arrays

**2015-01-03 02:12:27****SoItBegins****2081**View**2**Score**3**Answer- Tags: python arrays list numpy duplicate-removal

#### 4 Answered Questions

### [SOLVED] Are element-wise operations faster with NumPy functions than operators?

**2014-09-12 21:36:41****Gyan Veda****3254**View**8**Score**4**Answer- Tags: python arrays performance numpy element

## 2 comments

## @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`

creatorscouldhave 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.

If you use

The function call will result in passing [1,2,3,4,5] to

objectand [6,7,8,9,10] todtype, 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)