gpt4 book ai didi

python - 不理解 scipy.mgrid[1 :6:4j], j 这里的意思是什么?

转载 作者:行者123 更新时间:2023-12-01 03:35:38 25 4
gpt4 key购买 nike

我无法理解下面的代码。这里的步进参数是怎么计算的呢? j 是做什么用的?这不是一个复数吗?

import scipy
scipy.mgrid[1:6:4j]

最佳答案

scipy.mgrid[1:6:4j] 构造一个长度为 4 的列表,其中第一个元素为 1,最后一个元素是 6 并且步长被适当计算(如 (last-first)/(n-1))

>>> help(scipy.mgrid)

... if the step length is a complex number (e.g. 5j), then the integer part of its magnitude is interpreted as specifying the number of points to create between the start and stop values, where the stop value is inclusive.

该文档有点误导。如果我们从字面上理解,那么 scipy.mgrid[1:6:4j] 应该在 1 和 6 之间创建 4 个值 (2, 3, 4, 5),结果为 [1 , 2, 3, 4, 5, 6] )。

关于python - 不理解 scipy.mgrid[1 :6:4j], j 这里的意思是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40418625/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com