Python 3.1 (r31:73574, Jun 26 2009, 20:21:35) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 2/2
1.0
Run Code Online (Sandbox Code Playgroud)
这是有意的吗?我强烈记得早期版本的回归int/int=int?我应该怎么做,是否有新的分区运算符或者我必须总是演员?
我试图将一组数字从-100标准化为0到10-100的范围,并且只是注意到即使没有变量,也没有评估我期望它的方式:
>>> (20-10) / (100-10)
0
Run Code Online (Sandbox Code Playgroud)
浮动部门也不起作用:
>>> float((20-10) / (100-10))
0.0
Run Code Online (Sandbox Code Playgroud)
如果除法的任何一方被强制转换为浮点数,它将起作用:
>>> (20-10) / float((100-10))
0.1111111111111111
Run Code Online (Sandbox Code Playgroud)
第一个示例中的每一侧都评估为int,这意味着最终答案将被转换为int.因为0.111小于.5,所以它会变为0.在我看来,这不是透明的,但我想这就是它的方式.
解释是什么?
除了标准+,-,*和/运营商; 但什么是这些均值(**,^,%,//)?
>>> 9+float(2) # addition
11.0
>>> 9-float(2) # subtraction
7.0
>>> 9*float(2) # multiplication
18.0
>>> 9/float(2) # division
4.5
>>>
>>> 9**float(2) # This looks like a square, (i.e. power 2)
81.0
>>> 9**float(3) # So ** is equivalent to `math.pow(x,p)` ?
729.0
Run Code Online (Sandbox Code Playgroud)
又如何^操作?
>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u` …Run Code Online (Sandbox Code Playgroud) 我正在研究环的强度如何根据角度而变化.这是一个图像的示例:
我想做的是从该甜甜圈的中心取一圈值并绘制它们与角度的关系.我目前正在做的是使用scipy.ndimage.interpolation.rotate并通过环径向切片,并提取两个峰的最大值并绘制那些与角度的关系.
crop = np.ones((width,width)) #this is my image
slices = np.arange(0,width,1)
stack = np.zeros((2*width,len(slices)))
angles = np.linspace(0,2*np.pi,len(crop2))
for j in range(len(slices2)): # take slices
stack[:,j] = rotate(crop,slices[j],reshape=False)[:,width]
Run Code Online (Sandbox Code Playgroud)
但是我认为这不是我正在寻找的东西.我主要是如何提取我想要的数据.我也试过应用一个看起来像这样的面具;
到图像,但后来我不知道如何以正确的顺序获取该掩码内的值(即按照增加角度0 - 2pi的顺序)
任何其他想法都会有很大的帮助!
我正在尝试计算输入的位数。但是,每当我输入10或11或任何两位数时,输出都是325. 为什么不起作用?
inputnumber = int(input())
countnumber = inputnumber
digitcount = 0
while countnumber > 0:
digitcount += 1
countnumber = countnumber/10
print(digitcount)
# result is 325 when input is 10 or 11
Run Code Online (Sandbox Code Playgroud)