user2758034
user2758034

Reputation:

np.array returning numpy.ndarray with "..."

I created a script to generate a list:

import random

nota1 = range (5, 11)
nota2 = range (5, 11)
nota3 = range (5, 11)
nota4 = range (0, 2)

dados = []

for i in range(1000):

    dados_dado = []

    n1 = random.choice(nota1)
    n2 = random.choice(nota2)
    n3 = random.choice(nota3)
    n4 = random.choice(nota4)

    n1 = float (n1)
    n2 = float (n2)
    n3 = float (n3)
    n4 = float (n4)

    dados_dado.append (n1)
    dados_dado.append (n2)
    dados_dado.append (n3)
    dados_dado.append (n4)

    dados.append (dados_dado)

When i print type (dados) python return: <type 'list'>, a huge list that looks like this:

[[5.0, 8.0, 10.0, 1.0], [8.0, 9.0, 9.0, 1.0], [7.0, 5.0, 6.0, 1.0], [5.0, 8.0, 7.0, 0.0], [9.0, 7.0, 10.0, 0.0], [6.0, 7.0, 9.0, 1.0], [6.0, 9.0, 8.0, 1.0]]

I need to transform it to <type 'numpy.ndarray'> so i made :

data = np.array(dados)

What i expected to return was something like this:

 [[ 6.8  3.2  5.9  2.3]
 [ 6.7  3.3  5.7  2.5]
 [ 6.7  3.   5.2  2.3]
 [ 6.3  2.5  5.   1.9]
 [ 6.5  3.   5.2  2. ]
 [ 6.2  3.4  5.4  2.3]
 [ 5.9  3.   5.1  1.8]]

But, what i get instead is:

 [[  7.  10.   6.   1.]
  [  8.   6.   6.   1.]
  [  6.   9.   5.   0.]
  ..., 
  [  9.   7.  10.   0.]
  [  6.   7.   9.   1.]
  [  6.   9.   8.   1.]]

What am i doing wrong?

Upvotes: 0

Views: 53

Answers (3)

hpaulj
hpaulj

Reputation: 231355

With your sample:

In [574]: dados=[[5.0, 8.0, 10.0, 1.0], [8.0, 9.0, 9.0, 1.0], [7.0, 5.0, 6.0, 1.
     ...: 0], [5.0, 8.0, 7.0, 0.0], [9.0, 7.0, 10.0, 0.0], [6.0, 7.0, 9.0, 1.0],
     ...:  [6.0, 9.0, 8.0, 1.0]]

In [575]: print(dados)
[[5.0, 8.0, 10.0, 1.0], [8.0, 9.0, 9.0, 1.0], [7.0, 5.0, 6.0, 1.0], [5.0, 8.0, 7.0, 0.0], [9.0, 7.0, 10.0, 0.0], [6.0, 7.0, 9.0, 1.0], [6.0, 9.0, 8.0, 1.0]]

convert it to an array, an see the whole thing. Your input didn't have decimals to numpy display omits those.

In [576]: print(np.array(dados))
[[  5.   8.  10.   1.]
 [  8.   9.   9.   1.]
 [  7.   5.   6.   1.]
 [  5.   8.   7.   0.]
 [  9.   7.  10.   0.]
 [  6.   7.   9.   1.]
 [  6.   9.   8.   1.]]

Replicate the list many times, and print display has this ..., rather than show 10,000 lines. That's nice isn't it?

In [577]: print(np.array(dados*1000))
[[  5.   8.  10.   1.]
 [  8.   9.   9.   1.]
 [  7.   5.   6.   1.]
 ..., 
 [  9.   7.  10.   0.]
 [  6.   7.   9.   1.]
 [  6.   9.   8.   1.]]

The full array is still there

In [578]: np.array(dados*1000).shape
Out[578]: (7000, 4)

The default is for numpy to add the ellipsis when the total number of entries is 1000. Do you really need to see all those lines?

That print standard can be changed, but I question whether you need to do that.

Upvotes: 1

Andrew
Andrew

Reputation: 1082

numpy.set_printoptions(precision=20)

Will give you more displayabilty, set precision as you desire.

Upvotes: 0

user2357112
user2357112

Reputation: 280291

Your array is fine. NumPy just suppresses display of the whole array for large arrays by default.

(If you actually were expecting your array to be short enough not to trigger this behavior, or if you were actually expecting it to have non-integer entries, you'll have to explain why you expected that.)

Upvotes: 0

Related Questions