0

With this code I want to generate some small numbers in Numpy array format:

np.random.seed(1)
syn0 = 2*np.random.random((315,1))-1

this gives me result like this:

[[-0.16595599]
 [ 0.44064899]
 [-0.99977125]
 [-0.39533485]
 [ 0.70648822]
 [-0.81532281]
 [-0.62747958]
 [ 0.30887855]
 [-0.20646505]
 [ 0.07763347]
 [-0.16161097]
      .
      .
      .

But when i change rows count to 316 and upper:

np.random.seed(1)
syn0 = 2*np.random.random((316,1))-1

Then I get results in this number format(power notation):

[[ -1.65955991e-01]
 [  4.40648987e-01]
 [ -9.99771250e-01]
 [ -3.95334855e-01]
 [ -7.06488218e-01]
 [ -8.15322810e-01]
 [ -6.27479577e-01]
 [ -3.08878546e-01]
 [ -2.06465052e-01]
 [  7.76334680e-02]
 [ -1.61610971e-01]
 [  3.70439001e-01]
         .
         .
         .

I know this is power notation format but why this happens? I dont need this format.Why this strange behavior happens?

2
  • 3
    It's just an representation. Nothing within your array changes. Why this is happening? Probably because the spread of values is likely to increase when taking more samples and there is some threshold within numpy's print function. Of course you can tell numpy to print it as you like. Consider reading the docs for this. Commented Nov 22, 2016 at 22:03
  • @sascha: but how i can see real values(in non-power format) Commented Nov 22, 2016 at 22:06

2 Answers 2

2

You can print a particular array without scientific notation using numpy.array2string:

print(np.array2string(x, suppress_small=True))

To not use scientific notation by default for all printing, use numpy.set_printoptions:

np.set_printoptions(suppress=True)

As to why this happens - when printing a floating point array the default behaviour is to use scientific notation if:

  • the minimum (absolute non zero) value to be printed is less than 0.0001; or
  • the ratio of the maximum (absolute non zero) value to minimum (absolute non zero) value is greater than 1000.

This behaviour is suppressed if suppress_small is passed to array2string (or suppress to set_printoptions)

Sign up to request clarification or add additional context in comments.

Comments

1

You can turn off scientific notation by changing numpy's print options:

np.set_printoptions(suppress=True)

syn0
>>> array([[-0.00083166],
           [ 0.45717134],
           [-0.58361112],
           [-0.50393288],
           [ 0.70334375],
           [-0.16830256],
           [ 0.23337013],
           [-0.53266772],
              ....

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.