小编unu*_*tbu的帖子

git藏匿问题

我正在运行msysgit 1.7.3.1.如果我运行stash apply,并且存在冲突,我的所有存储更改都会暂停.这是正确的行为吗?我发现它有点令人惊讶.

另一个问题:如果我存储了10个文件,并且其中一个文件存在冲突,则会在存在冲突时存储应用中止,或者是否应用所有非冲突文件.

最后,如果我执行以下操作:

git stash
git pull
git stash apply
Run Code Online (Sandbox Code Playgroud)

另一个开发人员删除了我藏匿的文件,然后我无法在此文件上应用存储.如何从藏匿处检索我的更改?

谢谢!

git conflict git-stash

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

如何表征最小二乘估计的适应度

我正在进行本地化项目并使用最小二乘估计来确定发射机的位置.我需要一种方法来统计我的程序中我的解决方案的"适应性",这可以用来告诉我是否有一个好的答案,或者我需要额外的测量,或者有不好的数据.我已经阅读了一些关于使用"确定系数"或R平方的内容,但未能找到任何好的例子.关于如何表征我是否有一个好的解决方案,或需要额外的测量的任何想法将非常感激.

谢谢!

我的代码给了我以下输出,

grid_lat和grid_lon对应于可能的目标位置的网格的纬度和经度坐标

grid_lat = [[ 38.16755799  38.16755799  38.16755799  38.16755799  38.16755799
  38.16755799]
  [ 38.17717199  38.17717199  38.17717199  38.17717199  38.17717199
    38.17717199]
  [ 38.186786    38.186786    38.186786    38.186786    38.186786    38.186786  ]
  [ 38.1964      38.1964      38.1964      38.1964      38.1964      38.1964    ]
  [ 38.20601401  38.20601401  38.20601401  38.20601401  38.20601401
    38.20601401]
  [ 38.21562801  38.21562801  38.21562801  38.21562801  38.21562801
    38.21562801]
  [ 38.22524202  38.22524202  38.22524202  38.22524202  38.22524202
    38.22524202]]

grid_lon = [[-75.83805812 -75.83006167 -75.82206522 -75.81406878 -75.80607233
    -75.79807588]
  [-75.83805812 -75.83006167 -75.82206522 -75.81406878 -75.80607233
    -75.79807588]
  [-75.83805812 -75.83006167 -75.82206522 -75.81406878 -75.80607233
    -75.79807588]
  [-75.83805812 -75.83006167 -75.82206522 …
Run Code Online (Sandbox Code Playgroud)

python statistics optimization numpy scipy

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

为多个数据库设置MySQLdb连接对象

这个问题可能很无聊.

而不是硬编码MySQLdb连接对象:例如,

db = MySQLdb.connect('localhost','name','pwrd','db_name')
Run Code Online (Sandbox Code Playgroud)

如何设置它以便我可以从列表或其他变量中指定db_name(或连接对象的任何其他部分).例如:

for NAME from list_of_names:
    db = MySQLdb.connect('localhost', 'name', 'pwrd', NAME)
Run Code Online (Sandbox Code Playgroud)

python database-connection mysql-python

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

Python inspect.getmembers在与装饰器一起使用时不返回实际的函数

我有三个python函数:

def decorator_function(func)
  def wrapper(..)
    return func(*args, **kwargs)
  return wrapper

def plain_func(...)

@decorator_func
def wrapped_func(....)
Run Code Online (Sandbox Code Playgroud)

在模块A内

现在我想获得这个模块A中的所有函数,我这样做:

for fname, func in inspect.getmembers(A, inspect.isfunction):
  # My code
Run Code Online (Sandbox Code Playgroud)

这里的问题是func的值不是我想要的.

它将是decorator_function,plain_func和wrapper(而不是wrapped_func).

如何确保返回wrapped_func而不是包装?

python decorator inspect

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

使用 matplotlib 和 twinx 进行光标跟踪

I would like to track the coordinates of the mouse with respect to data coordinates on two axes simultaneously. I can track the mouse position with respect to one axis just fine. The problem is: when I add a second axis with twinx(), both Cursors report data coordinates with respect to the second axis only.

For example, my Cursors (fern and muffy) report the y-value is 7.93

Fern: (1597.63, 7.93)
Muffy: (1597.63, 7.93)
Run Code Online (Sandbox Code Playgroud)

If I use: …

python matplotlib

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

列表到ndarray

我试图在scipy中使用kmeans聚类,正是这里的一个:

http://docs.scipy.org/doc/scipy/reference/generated/scipy.cluster.vq.kmeans.html#scipy.cluster.vq.kmeans

我想要做的是转换列表列表,如下所示:

data without_x[
[0, 0, 0, 0, 0, 0, 0, 20.0, 1.0, 48.0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1224.0, 125.5, 3156.0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 22.5, 56.0, 41.5, 85.5, 0, 0, 0, 0, 0, 0, 0, 0, 1495.0, 3496.5, 2715.0, 5566.5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
]
Run Code Online (Sandbox Code Playgroud)

进入一个ndarry,以便与Kmeans方法一起使用.当我尝试将列表列表转换为ndarray时,我得到一个空数组,从而排除了整个分析.ndarray的长度是可变的,它取决于收集的样本数量.但我可以轻松地使用len(data_without_x)

这是返回空列表的代码片段. …

python numpy scipy multidimensional-array k-means

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

字典无法识别浮点键

我有一本名为 G 的字典。当我输入 时G. keys (),输出的示例如下:

>>> G.keys ()
[(1490775.0, 12037425.0), (1493775.0, 12042675.0), (1481055.0, 12046305.0), (1503105.0, 12047415.0), (1488585.0, 12050685.0), (1483935.0, 12051405.0),...
Run Code Online (Sandbox Code Playgroud)

当我使用该操作时,key in G结果是错误的。

>>> (1490775.0, 12037425.0) in G
False
Run Code Online (Sandbox Code Playgroud)

为什么我的字典无法识别我的按键?

>>> type (G.keys()[0])
<type 'numpy.void'>
>>> type (G.keys()[0][0])
<type 'numpy.float64'>
>>> type (G.keys()[0][1])
<type 'numpy.float64'>
type(G)
<type 'dict'>
Run Code Online (Sandbox Code Playgroud)

python floating-point dictionary numpy key

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

Python 颜色条刻度标有 +1 的偏移量而不是指定的值

我正在尝试使用 python 绘制矢量场散度的轮廓图,然后向该图中添加一个颜色条。我的级别旨在从 -0.01 到 0.01 在零附近对称。

这是我的代码的一部分:

div_levs = [-0.01, -0.005, -0.0025, 0.0025, 0.005, 0.01]
col = ['Blue', 'SteelBlue', 'White', 'Orange', 'Red']
c = plt.contourf(iwrf['x'], iwrf['y'], np.squeeze(iwrf['DIV'][ind_lev,:,:]), 
                 levels=div_levs, colors=col, extend='both')
c.cmap.set_over('Magenta') 
c.cmap.set_under('MidnightBlue')     
bar = plt.colorbar(ticks=div_levs)
bar.set_label('1/s') 
Run Code Online (Sandbox Code Playgroud)

如果我执行 python 脚本,它就可以工作,并且所有内容都以正确的方式绘制,但颜色图标有:

0.9900, 0.9950, 0.9975, 1.025, 1.0050, 1.0100
Run Code Online (Sandbox Code Playgroud)

并且在颜色条的顶部显示“-1”。

我已经尝试了很多,包括在创建颜色条后设置它的刻度,或者在调试模式下设置刻度,但似乎没有任何改变这种行为。

对此有何想法?

python matplotlib colorbar

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

如何快速将像"001100"这样的字符串转换为numpy.array([0,0,1,1,0,0])?

我有一个由0和1组成的字符串,就像'00101'.我想将它转换为numpy数组numpy.array([0,0,1,0,1].

我正在使用for循环:

import numpy as np
X = np.zeros((1,5),int)
S = '00101'
for i in xrange(5):
    X[0][i] = int(S[i])
Run Code Online (Sandbox Code Playgroud)

但由于我有很多字符串,每个字符串的长度是1024,这种方式非常慢.有没有更好的方法来做到这一点?

python format types numpy type-conversion

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

注释中的python无效语法

使用空闲 Python 3.4.3。这是一个脚本,它给用户一个小测验,然后计算有多少是正确的。在我的脚本运行之前,我在评论中遇到了无效的语法错误。这是评论周围的整个代码。具体评论在下面一行score = decimal.Decimal(score)

score = amountright/7*100 """this takes the amount of questions the user got right, divides it by 7 (the total number of questions), then multiplies it by 100 to get a percentage correct and stores it in the variable score"""
import decimal """this will import a function to round off the final percentage to a whole number instead of an unnecessarily long decimal"""
score = decimal.Decimal(score)
"""this redefines the score variable as some sort …
Run Code Online (Sandbox Code Playgroud)

python syntax comments python-idle

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