Python中文
首页
教程
问答
标签
搜索
登录
注册
为什么当x在numpy中增加时,2上升到x会给出负值?
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>Numpy将包含提升为自然数的2的列表的数组作为负值。2怎么可能被提升到正数,比如1000是负数?你知道吗</p> <p>我有一个数组'x',我们用来绘制从1到n的x轴值。 对于数组x中的每个值,我们取x**(2**x),即x提升到(2提升到x),并将其用作y轴值。你知道吗</p> <p>情形1:对于x∈[1,50)</p> <p>我使用了下面的代码,输出是正确的,因为的输出中没有负值np.功率(2,x)。你知道吗</p> <pre><code>x = np.array([x for x in range(1, 50)]) print(np.power(2, x)) x2x = np.power(x, np.power(2, x)) plt.plot(x, x, label = 'f(n) = n') plt.plot(x, x2x, label = 'f(n) = x**(2**x)') plt.legend() plt.show() </code></pre> <p>输出: <img src="https://github.com/aishwarya34/AlgorithmsIlluminated/blob/master/images/so_issue1.png" alt="No negative values in the output "/></p> <p><a href="https://github.com/aishwarya34/AlgorithmsIlluminated/blob/master/images/so_issue1.png" rel="nofollow noreferrer">Link to output</a></p> <p>情形2:对于x∈[1100]</p> <p>我使用了下面的代码,并且在的输出中有负值np.功率(2,x)等等np.功率(十),np.功率(2,x))</p> <pre><code>x = np.array([x for x in range(1, 100)]) print(np.power(2, x)) x2x = np.power(x, np.power(2, x)) plt.plot(x, x, label = 'f(n) = n') plt.plot(x, x2x, label = 'f(n) = x**(2**x)') plt.legend() plt.show() </code></pre> <p>输出: <img src="https://github.com/aishwarya34/AlgorithmsIlluminated/blob/master/images/so_issue2.png" alt="Negative values in the output "/></p> <p><a href="https://github.com/aishwarya34/AlgorithmsIlluminated/blob/master/images/so_issue2.png" rel="nofollow noreferrer">Link to output</a></p> <p>如果x总是正数且不递减,而2是常量且为正数,那么为什么在numpy中2被提升为正数而得到负输出?你知道吗</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>整数可能溢出了。32位整数只能包含高达~2.1b的值,如果溢出,它将返回负数。你知道吗</p> <p>设置<code>dtype=int64</code>可以解决您的问题。如果不是,就使用python整数(<code>dtype=object</code>)。它们的效率不高,但它们可以容纳尽可能多的数据。你知道吗</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
VirtualEnvRapper错误:路径python2(来自python=python2)不存在
8 回答
virtualenvs上的pyinstaller,没有名为导入错误的模块
7 回答
virtualenvs是否可以退回到用户包而不是系统包?
10 回答
virtualenvwrapper CentOS7
10 回答
virtualenvwrapper IOError:[Errno 13]权限被拒绝
10 回答
virtualenvwrapper mkproject和shell在windows中的启动问题?
4 回答
virtualenvwrapper mkvirtualenv不工作但没有错误
3 回答
Virtualenvwrapper python bash
9 回答
virtualenvwrapper:“workon”何时更改到项目目录?
9 回答
virtualenvwrapper:mkvirtualenv可以工作,但是rmvirtualenv返回bash:没有这样的文件或目录
10 回答
virtualenvwrapper:virtualenv信息存储在哪里?
9 回答
virtualenvwrapper:命令“python设置.pyegg_info“失败,错误代码为1
2 回答
virtualenvwrapper:如何将mkvirtualenv的默认Python版本/路径更改为ins
9 回答
Virtualenvwrapper:模块“pkg_resources”没有属性“iter_entry_points”
7 回答
Virtualenvwrapper:没有名为virtualenvwrapp的模块
2 回答
Virtualenvwrapper.bash_profi的正确设置
10 回答
Virtualenvwrapper.hook:权限被拒绝
10 回答
virtualenvwrapper.sh:fork:资源暂时不可用Python/Djang
6 回答
Virtualenvwrapper.shlssitepackages命令不工作
7 回答
Virtualenvwrapper.sh函数在bash sh中不可用
2 回答