小编Sea*_*ean的帖子

如何在numpy矩阵中找到最小值?

嘿,这是一个快速简单的问题......我怎样才能找到这个矩阵的最小值,不包括0?如,8

arr = numpy.array([[  0.,  56.,  20.,  44.],
                   [ 68.,   0.,  56.,   8.],
                   [ 32.,  56.,   0.,  44.],
                   [ 68.,  20.,  56.,   0.]])
Run Code Online (Sandbox Code Playgroud)

python arrays numpy matrix minimum

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

在Java中提取int的数字

所以,如果我有一个输入的整数:

int num_1 = 128
Run Code Online (Sandbox Code Playgroud)

我如何能够解析数字并获得1,2和8,并将它们分配给不同的变量?

谢谢!

java string parsing integer

10
推荐指数
3
解决办法
4万
查看次数

Python,如何填充空 numpy 数组中的列

我通常会去

http://docs.scipy.org
Run Code Online (Sandbox Code Playgroud)

获取此信息,但他们的网站由于某种原因关闭了:/

但是我如何才能填充 numpy 矩阵中的整列呢?

a = numpy.zeros(shape=(100,10))
a[0] = [1,2,3,4,5,6,7,8,9,0]
Run Code Online (Sandbox Code Playgroud)

填满一行,但是如何填满一列呢?

python arrays numpy

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

如何用2个变量检查​​dict.has_key(k,x)

我已经形成了一个字典,其中2个键分配给单个字典值,例如:

my_dict[x, y] = ...
my_dict[a, u] = ...
Run Code Online (Sandbox Code Playgroud)

现在我如何能够将这个has_key()方法用于2个关键变量,x和y如下:

if my_dict.has_key(x,y) == True:
    Do Something
else:
    Do something else
Run Code Online (Sandbox Code Playgroud)

d是一个矩阵,它使用我从变量f和g调用的pdict值,但你需要知道的是它们是变量名x,y被用作pdict中的键值.

python variables dictionary key

5
推荐指数
2
解决办法
1490
查看次数

如何在标签下方水平对齐单选按钮

因此,我使用以下HTML在jsp中的相应标签下方水平居中显示4个单选按钮:

<s:form action="markUser" name="markUser" method="post" namespace="/secure/admin">
    <div id="radioGroup">

        <label for="markStudent">Mark User as Student</label>
        <input type="radio" name="mark" id="markStudent" value="Student" />

        <label for="markAdmin">Mark User as Admin</label>
        <input type="radio" name="mark" id="markAdmin" value="Admin" />

        <label for="markService">Mark User as Service</label>
        <input type="radio" name="mark" id="markService" value="Service" />

        <label for="markNull">Mark User as Null</label>
        <input type="radio" name="mark" id="markNull" value="Null" />

    </div>
</s:form>
Run Code Online (Sandbox Code Playgroud)

和CSS:

.radioGroup label {
  display: inline-block;
  text-align: center;
  margin: 0 0.2em;
}
.radioGroup label input[type="radio"] {
  display: block;
  margin: 0.5em auto;
}
Run Code Online (Sandbox Code Playgroud)

但是我不断出现如下所示的未对齐按钮

它不会水平:/

我在这里可能会缺少什么?

html css alignment radio-button

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

流行指数超出范围

N=8
f,g=4,7
indexList = range(N)
print indexList
print f, g
indexList.pop(f)
indexList.pop(g)
Run Code Online (Sandbox Code Playgroud)

在这段代码中,我收到一条错误,指出gin 的pop索引indexList超出范围.这是输出:

[0, 1, 2, 3, 4, 5, 6, 7]
4 7
Traceback (most recent call last):
indexList.pop(g)
IndexError: pop index out of range
Run Code Online (Sandbox Code Playgroud)

我不明白,g有一个值为7,列表包含7个值,为什么它不能返回列表中的7?

python indexing list range

4
推荐指数
2
解决办法
2万
查看次数

如何在方法调用中使用关键字arg之后的非关键字arg?

所以我有一个定义如下的函数:

def getDistnace(self, strings, parentD, nodeName, nodeDistance):
Run Code Online (Sandbox Code Playgroud)

我称之为:

Node.getDistnace(newNode, strings, parentD, nodeName=None, nodeDistance=None)
Run Code Online (Sandbox Code Playgroud)

Node.getDistnace(node, strings=None, parentD=None, nodeName, nodeDistance)
Run Code Online (Sandbox Code Playgroud)

这两个来自其他两个不同的功能.但我的问题是我得到一个错误,说明有一个non-keyword arg after keyword arg.

有没有办法解决这个错误?第一个Node.getDistnacestringsparentDgetDistance,第二个Node.getDistnacenodeNamenodeDistance的功能.

python arguments function keyword

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

Python列表迭代

所以我有一个高度列表:

heights = [1, 2, 3, 5, 7, 8, 8, 13]
Run Code Online (Sandbox Code Playgroud)

并且我使用此函数将每个高度整数值及其索引存储在名为Node的类中的列表中.

def initializeNodes(heights):
    ans = []
    for height in heights:
        ans.append(Node(heights.index(height), height))
    return ans
Run Code Online (Sandbox Code Playgroud)

但我的问题是,因为它们是列表中的两个8,它在列表中给它们两个相同的前8个位置:

0 1
1 2
2 3
3 5
4 7
5 8
5 8
7 13
Run Code Online (Sandbox Code Playgroud)

我怎么能绕过这个?谢谢!

python iteration list

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

比较Python中的3个列表

以下代码比较了三个列表,motherList fatherlistsonList检查是否每个值都以一次或一次sonList表示.motherListfatherList

def compareList(motherList, fatherList, sonList):
    count = 0
    for x in sonList:
            if x in motherList and x in fatherList:
                    count = 2
            elif x in motherList or x in fatherList:
                    count += 1
    if count >= 2:
            ans = "Mendelion"
    else:
            ans = "Non-Medelian"

    print"{0} {1} \t {2} \t {3}".format(motherList, fatherList, sonList, ans)
Run Code Online (Sandbox Code Playgroud)

输出:

['0']        ['0']         ['4']         Non-Mendelion
['2', '6']   ['0']         ['0', '2']    Mendelion
['1']        ['0']         ['1']         Non-Medelian
['-1', '2'] …
Run Code Online (Sandbox Code Playgroud)

python compare list

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

如何从Python中的文本文件导入Matrix

嘿,这可能是一个简单的问题,但我以前从未将任何文件导入Python.

所以我在一个文本文件中有一个numpy Matrix,命名dmatrix.txt,那么我怎样才能将文件导入Python并使用矩阵?

我正在尝试使用numpy.load(),但我不确定如何使用它.

python import load numpy matrix

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