Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filling array with zeros in numpy

h = numpy.zeros((2,2,2)) 

What is the last 2 for? Is it creating a multidimensional array or something?

Output:

array([[[ 0.,  0.],
    [ 0.,  0.]],
   [[ 0.,  0.],
    [ 0.,  0.]]])

If it is creating number of copies, then what is happening when i do the following?

h = numpy.zeros((2,2,1))

Output:

array([[[ 0.],
    [ 0.]],
   [[ 0.],
    [ 0.]]])

I understand that it is getting filled by zeros, and the first two values are specifying the row and column, what about the third? Thank you in advance. And I tried Google, but I could not word my questions.

like image 305
hlkstuv_23900 Avatar asked Jan 30 '14 12:01

hlkstuv_23900


1 Answers

by giving three arguments you're creating a three-dimensional array:

numpy.array((2,2,2)) results in an array of size 2x2x2:

  0---0
 /   /|
0---0 0
|   |/
0---0

numpy.array((2,2,1)) results in an array of size 2x2x1:

0---0
|   |
0---0

numpy.array((2,1,2)) results in an array of size 2x2x1:

  0---0
 /   /
0---0

numpy.array((1,2,2)) results in an array of size 2x2x1:

  0
 /|
0 0
|/
0

in these representations the matrix "might look like numpy.array((2,2))" (a 2x2 array) however the underlying structure is still three dimensional.

like image 152
Nils Werner Avatar answered Sep 30 '22 08:09

Nils Werner