You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

技术问询:axis与dim关键字参数的使用存在哪些差异?

Axis vs Dim in Deep Learning Frameworks

Great question! This is a super common point of confusion when jumping between different frameworks or even different APIs within the same framework—let’s unpack it clearly.

At their core, axis and dim refer to exactly the same thing: they specify which dimension of a tensor you want an operation to run along. The difference is purely a naming convention, not a functional one.

Here’s how this plays out in common tools:

  • TensorFlow: You’ll see both used, but there’s a trend toward standardizing on axis in newer APIs. For example, the old tf.nn.softmax uses dim, but modern functions like tf.reduce_mean or tf.argmax prioritize axis (though many still accept dim as a legacy alias). Some TF docs even mark dim as deprecated, so it’s safer to use axis for new code.
  • PyTorch: The framework consistently uses dim across almost all its operations—you’ll rarely see axis here. So torch.softmax(input, dim=-1) does the exact same thing as TensorFlow’s version, just with the parameter named differently.
  • NumPy: It’s always used axis, which is probably where the convention originated. Most early deep learning frameworks took inspiration from NumPy, so axis was the first common term.

A quick note to avoid mistakes: Even though they mean the same thing, you can’t pass both parameters to the same function. For example, tf.nn.softmax(logits, axis=-1, dim=-1) will throw an error—pick one (preferably the one the docs recommend for that specific function).

In short: No functional difference, just different names for the same concept. Follow the naming convention of the API you’re using, and you’ll be good to go!

内容的提问来源于stack exchange,提问作者figs_and_nuts

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 06:34:55