PyTorch is giving me a different value for a scalar

Mike

When I create a tensor from float using PyTorch, then cast it back to a float, it produces a different result. Why is this, and how can I fix it to return the same value?

num = 0.9
float(torch.tensor(num))

Output:

0.8999999761581421
Berriel

This is a floating-point "issue" and you read more about how Python 3 handles those here.

Essentially, not even num is actually storing 0.9. Anyway, the print issue in your case comes from the fact that num is actually double-precision and torch.tensor uses single-precision by default. If you try:

num = 0.9
float(torch.tensor(num, dtype=torch.float64))

you'll get 0.9.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

repeater not giving me new value during editing in asp.net

분류에서Dev

SqlCeCommand keeps giving me an exception

분류에서Dev

Nginx Autoindex giving me a 403

분류에서Dev

C pointer giving random value

분류에서Dev

Checking for repeated characters not giving me the desired output

분류에서Dev

Why is my Makefile giving me problems?

분류에서Dev

GPT2 on Hugging face (pytorch transformers) RuntimeError : grad can be implicitly created only for scalar outputs

분류에서Dev

php converting string to int not giving the right value

분류에서Dev

Android list adapter - only giving one value

분류에서Dev

How to import a function with scalar return value in EF 5

분류에서Dev

Don't understand why my code giving me an IndexError

분류에서Dev

Crystal Reports keeps giving me: Could not load file or assembly

분류에서Dev

Heapify is giving me an incorrect output for a min-heap

분류에서Dev

Woocommerce add_to_cart giving me fatal error

분류에서Dev

Why these expressions are giving me output instead of compile error?

분류에서Dev

PHP function giving me exception when trying to display on HTML

분류에서Dev

LocationManager giving 2 different values for Lat and Long for same location

분류에서Dev

Underscore template iteration with `tr` element on different datas giving wrong result

분류에서Dev

Getting attribute using XPath and giving inner text using value attribute

분류에서Dev

php submit only giving last value from array that populates form

분류에서Dev

Dataframe.isin() giving this error: The truth value of a DataFrame is ambiguous

분류에서Dev

관계가있는 상위 N 개 선택 @scalar_value = count (*)

분류에서Dev

Displaying image in tooltip is giving me a flickering effect when hovered over the content

분류에서Dev

Why is it giving me an error when i'm calling it from inside the 'student class?

분류에서Dev

Why isn't IPython giving me a full traceback for a module I've written?

분류에서Dev

why does my float variable statement keeps on giving me an 'Cannot implicitly convert type double to float' error?

분류에서Dev

Why is my constructed formula giving different results than the same formula as UDF in Excel?

분류에서Dev

variable value based on value in different dataframe

분류에서Dev

Datetimepicker set value of different format

Related 관련 기사

  1. 1

    repeater not giving me new value during editing in asp.net

  2. 2

    SqlCeCommand keeps giving me an exception

  3. 3

    Nginx Autoindex giving me a 403

  4. 4

    C pointer giving random value

  5. 5

    Checking for repeated characters not giving me the desired output

  6. 6

    Why is my Makefile giving me problems?

  7. 7

    GPT2 on Hugging face (pytorch transformers) RuntimeError : grad can be implicitly created only for scalar outputs

  8. 8

    php converting string to int not giving the right value

  9. 9

    Android list adapter - only giving one value

  10. 10

    How to import a function with scalar return value in EF 5

  11. 11

    Don't understand why my code giving me an IndexError

  12. 12

    Crystal Reports keeps giving me: Could not load file or assembly

  13. 13

    Heapify is giving me an incorrect output for a min-heap

  14. 14

    Woocommerce add_to_cart giving me fatal error

  15. 15

    Why these expressions are giving me output instead of compile error?

  16. 16

    PHP function giving me exception when trying to display on HTML

  17. 17

    LocationManager giving 2 different values for Lat and Long for same location

  18. 18

    Underscore template iteration with `tr` element on different datas giving wrong result

  19. 19

    Getting attribute using XPath and giving inner text using value attribute

  20. 20

    php submit only giving last value from array that populates form

  21. 21

    Dataframe.isin() giving this error: The truth value of a DataFrame is ambiguous

  22. 22

    관계가있는 상위 N 개 선택 @scalar_value = count (*)

  23. 23

    Displaying image in tooltip is giving me a flickering effect when hovered over the content

  24. 24

    Why is it giving me an error when i'm calling it from inside the 'student class?

  25. 25

    Why isn't IPython giving me a full traceback for a module I've written?

  26. 26

    why does my float variable statement keeps on giving me an 'Cannot implicitly convert type double to float' error?

  27. 27

    Why is my constructed formula giving different results than the same formula as UDF in Excel?

  28. 28

    variable value based on value in different dataframe

  29. 29

    Datetimepicker set value of different format

뜨겁다태그

보관