小编Bob*_*ger的帖子

我收到错误<string>:149:RuntimeWarning:生成列表时在sqrt中遇到无效值

def ellipse(numPoints, genX=np.linspace, HALF_WIDTH=10, HALF_HEIGHT=6.5):
    xs = 10.*genX(-1,1,numPoints)
    ys = 6.5*np.sqrt(1-(xs**2))
    return(xs, ys, "-")
Run Code Online (Sandbox Code Playgroud)

我收到一个错误,指出在squareroot中遇到无效值.我看不出它是什么.

sqrt(0) = 0
6.5*sqrt(1- (-1**2)) = 0
Run Code Online (Sandbox Code Playgroud)

他们应该工作,但y值有问题,他们正在返回"南"

python numpy sqrt

8
推荐指数
1
解决办法
1万
查看次数

从子列表列表中选择最小值并显示该子列表中具有最小值的另一个值

假设我有一个清单:

stuff =  [[5,3,8],[2,4,7],[14,5,9]]
Run Code Online (Sandbox Code Playgroud)

其中每个子列表的形式为[x,y,z].

我想找到子列表中第三个条目的该列表的最小值,即z=7。然后我想打印出该子列表的第一个值x

ex) z 的最小值出现在 处x = 2

python list minimum selection

3
推荐指数
1
解决办法
2048
查看次数

通过一些检查得到一组数字之间的原始输入

我试图让用户输入2个数字,这些数字被分成2个整数的列表,但不幸的是我似乎无法让它们变成整数,但我也不确定我的检查以及它是否会终止正确地返回我需要的东西.

def getlohiint():
    lohilist = []
    lohi = raw_input("Enter min and max number of points to use(e.g., 2 1000): ")
    lohilist = lohi.split()
    for x in lohilist:
        int(x)
    if lohilist[0]<=2 and lohilist[1]<=1000 and lohilist[0]<lohilist[1]:
        break
    else:
        prompt = "%d is not in the range of 2 to 1000; "
        prompt1 = "must be at least 2"
        prompt2 = "must be no higher than 1000"
        if lohilist[0]<2:
            print prompt + prompt1
        elif lohilist[1]>1000:
            print prompt + prompt2
        else:
            print prompt + …
Run Code Online (Sandbox Code Playgroud)

python if-statement function

2
推荐指数
1
解决办法
199
查看次数

如何检查列表中是否存在字符串

我的代码的重点是检查4个单词的句子以及它是否长4个单词.

import random
import time
import urllib

numwords = 4
#getWordList
wordlist = []
def getWordList() :

    url = "some word list url"
    flink = urllib.urlopen(url)
    #print "Reading words from %s" % url
    words = [ ]            # word list
    for eachline in flink :
        text = eachline.strip()
        text = text.replace('%','')
        words += [text.lower()]
    flink.close()
    #print "%d words read" % len(words)
    words.append('i','am','an','to')
    return wordlist


warning = "\n"
prompt = "Enter a sentence with four words: "
while warning:
    usrin = …
Run Code Online (Sandbox Code Playgroud)

python string list

0
推荐指数
1
解决办法
133
查看次数

是什么!=在Python中做/平均

我在python参考指南中看到了此代码,但没有描述。

我被问到这样的问题:

print 2 and 1-2 !=3
Run Code Online (Sandbox Code Playgroud)

它返回了True,但是为什么呢?

python math

-17
推荐指数
1
解决办法
4万
查看次数

标签 统计

python ×5

list ×2

function ×1

if-statement ×1

math ×1

minimum ×1

numpy ×1

selection ×1

sqrt ×1

string ×1