TensorFlow文档中整数值与数值下划线的含义探究:下划线是否等同于小数点?
Underscores in Numeric Values in TensorFlow Documentation: What They Mean
Hey there! Awesome question—those underscores you're seeing in numbers (like 10_000 for batch sizes) have nothing to do with decimal points. Let's break this down simply:
- It's a Python readability feature: Introduced in Python 3.6, underscores act as digit separators for numeric literals. They’re purely there to make large numbers easier to scan at a glance—think of them like commas you’d use when writing numbers (e.g., 10,000 becomes
10_000in code). - No impact on value or type: The Python interpreter completely ignores these underscores. So
10_000is identical to10000—same integer value, same data type. A decimal point (.) would change things entirely (e.g.,10.000is a float equal to 10.0), but underscores don’t alter the number at all. - Why TensorFlow uses it: You’ll spot this for values like batch sizes, dataset counts, or hyperparameters where large numbers are common. It’s a standard Python best practice now, so it’s used across TensorFlow docs and other Python-based ML codebases to keep code clean and easy to read.
This is just syntax sugar for readability—no hidden functionality here!
内容的提问来源于stack exchange,提问作者sakeesh
相关产品推荐
相关产品推荐

