Converting e-07 to decimals

401 views
Skip to first unread message

varghese alex

unread,
Jul 1, 2016, 6:21:56 AM7/1/16
to torch7
Hi;

Could someone help how to convert a tensor 

C=[6.5522e-01  3.4683e-05  3.4471e-01  3.0375e-05  4.6763e-07] to its equivalent decimal format?

Regards
Varghese

Adam Paszke

unread,
Jul 1, 2016, 7:24:55 AM7/1/16
to torch7 on behalf of varghese alex
Hi,

It’s essentially a scientific notation (https://en.wikipedia.org/wiki/Scientific_notation). The part before “e” is mantissa, and the part after it is 10s exponent.
For example:
6.5522e-01 = 6.5522 * 10^(-1) = 0.65522
1.2345e+03 = 1.2345 * 10^(3) = 1234.5

Best,
Adam

--
You received this message because you are subscribed to the Google Groups "torch7" group.
To unsubscribe from this group and stop receiving emails from it, send an email to torch7+un...@googlegroups.com.
To post to this group, send email to tor...@googlegroups.com.
Visit this group at https://groups.google.com/group/torch7.
For more options, visit https://groups.google.com/d/optout.

varghese alex

unread,
Jul 1, 2016, 7:52:00 AM7/1/16
to torch7 on behalf of Adam Paszke
Hi Adam 

Thanks for the pointer ,

However I have a (5x1) tensor which can take any value
for example C0=[6.5522e-01  3.4683e-05  3.4471e-01  3.0375e-05  4.6763e-07]
                    C1=[6.5522e-08  7.4683e-06  7.4471e-05  3.0375e-05  4.6763e-07] 

I was in search of better technique to convert the tensor to their decimal values in one shot

Regards
Varghese

--
You received this message because you are subscribed to a topic in the Google Groups "torch7" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/torch7/LfFutpSjg-c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to torch7+un...@googlegroups.com.

Adam Paszke

unread,
Jul 1, 2016, 8:03:45 AM7/1/16
to torch7 on behalf of varghese alex
Hi,

If you want to do print the decimals you can try with something like this:

for i = 1, C:size(1) do
  print(string.format('%.20f', C[i]))
end

You can change 20 to any other number. It allows you to specify the number of decimal places you’d like to see.

Best,
Adam

varghese alex

unread,
Jul 2, 2016, 12:59:11 AM7/2/16
to torch7 on behalf of Adam Paszke
Thanks Adam;

Rather than printing the array, I prefer to store it in another array with 5 decimal points. Is that possible ?
Reply all
Reply to author
Forward
0 new messages