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

关于np.array([0,100])用作绘图X轴的疑问:是生成序列还是仅含两值?

Clarifying np.array([0,100]) for Plotting X-Axis

Hey there! Let me clear up this confusion for you right away:

np.array([0,100]) only contains two distinct values: 0 and 100 — it does NOT generate a continuous sequence of numbers from 0 to 100.

Why would someone use this for an X-axis?

This is typically used when you only need to plot data at those two specific X positions. For example:

  • You have two discrete data points (like measurements taken at 0 and 100 units of some variable)
  • You want to draw a straight line connecting two points, where the X coordinates are exactly 0 and 100

Here’s a quick code example to illustrate:

import numpy as np
import matplotlib.pyplot as plt

# X-axis has just two values: 0 and 100
x = np.array([0, 100])
# Corresponding Y-values
y = np.array([10, 30])

# This will draw a line from (0,10) to (100,30)
plt.plot(x, y)
plt.show()

If you wanted a sequence from 0 to 100...

You’d use functions like np.arange() or np.linspace() instead:

  • np.arange(0, 101) generates integers from 0 to 100 (step size of 1 by default)
  • np.linspace(0, 100, num=101) creates 101 evenly spaced points between 0 and 100 (inclusive)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.08 12:37:54