我有一个TOF频谱,我想用python(numpy)实现一个算法,它找到频谱的所有最大值并返回相应的x值.
我在网上查了一下,发现下面报告的算法.
这里的假设是,在最大值附近,之前的值与最大值之间的差值大于数字DELTA.问题是我的光谱由均匀分布的点组成,即使在最大值附近,也不会超过DELTA,函数peakdet返回一个空数组.
你知道如何克服这个问题吗?我非常感谢评论,以便更好地理解代码,因为我是python中的新手.
谢谢!
import sys
from numpy import NaN, Inf, arange, isscalar, asarray, array
def peakdet(v, delta, x = None):
maxtab = []
mintab = []
if x is None:
x = arange(len(v))
v = asarray(v)
if len(v) != len(x):
sys.exit('Input vectors v and x must have same length')
if not isscalar(delta):
sys.exit('Input argument delta must be a scalar')
if delta <= 0:
sys.exit('Input argument delta must be positive')
mn, mx = Inf, -Inf
mnpos, mxpos = NaN, …
Run Code Online (Sandbox Code Playgroud) 我想通过ansible获取在windows节点上创建的文件(info.txt)。我尝试使用 fetch 模块(它在 linux 节点上对我有用),它似乎不适用于 Windows 客户端。这是相关的代码:
task:
-name: Fetch a info file
fetch: src=C:\info.txt dest=/home/user flat=yes
Run Code Online (Sandbox Code Playgroud)
我没有收到错误,但未获取文件。我在本地机器上运行 ubuntu。难道我做错了什么?谢谢
这是使用 -vvv 选项运行的 playbook 的输出:
If (Test-Path -PathType Leaf "C:\info.txt")
{
$sp = new-object -TypeName System.Security.Cryptography.SHA1CryptoServiceProvider;
$fp = [System.IO.File]::Open("C:\info.txt[System.IO.Filemode]::Open, [System.IO.FileAccess]::Read);
[System.BitConverter]::ToString($sp.ComputeHash($fp)).Replace("-", "").ToLower();
$fp.Dispose();
}
ElseIf (Test-Path -PathType Container "C:\info.txt")
{
Write-Host "3";
}
Else
{
Write-Host "1";
}
<192.168.122.123> FETCH "C:\info.txt" TO "/home/diego/work/ansible_win/ex1"
Run Code Online (Sandbox Code Playgroud)
更改:[win1] => {“更改”:真,“校验和”:空,“dest”:“/home/diego/work/ansible_win/ex1”,“调用”:{“module_args”:{“dest” : "/home/diego/work/ansible_win/ex1", "flat": "yes", "src": "C:/info.txt"}, "module_name": "fetch"}, "md5sum": null , "remote_checksum": "9664e0d22d3e184eb206d60af29e340f620092d0", "remote_md5sum": null}
我正在尝试运行 PowerShell 脚本以owncloud-client
从 Windows 10 虚拟机中卸载。下面显示的代码可以在以下位置找到
https://chocolatey.org/packages/owncloud-client (tools\chocolateyUninstall.ps1)
我只想通过从 PowerShell 运行代码来测试代码,看看它是否确实卸载了软件。
$unfile = "ownCloud\uninstall.exe"
if (Test-Path "${Env:ProgramFiles(x86)}\$unfile") {
$unpath = "${Env:ProgramFiles(x86)}\$unfile"
} else {
$unpath = "${Env:ProgramFiles}\$unfile"
}
Uninstall-ChocolateyPackage 'owncloud-client' 'exe' '/S' "$unpath"
Run Code Online (Sandbox Code Playgroud)
我通过键入以下内容从包含该脚本的目录运行脚本:
.\chocolateyUninstall.ps1
Run Code Online (Sandbox Code Playgroud)
作为输出,我收到以下错误:
Uninstall-ChocolateyPackage is not recognized as the name of cmdlet, function, script file, or operable program.
Run Code Online (Sandbox Code Playgroud)
Uninstall-ChocolateyPacakge.ps1 软件包由 Chocolatey 提供。我检查了我的机器,这个包位于:
C:\ProgramData\chocolatey\helpers\functions\Uninstall-ChocolateyPackage.ps1
Run Code Online (Sandbox Code Playgroud)
但它仍然不被 powershell 识别为 cmdlet。我怎么解决这个问题?谢谢
我有一个嵌套字典,我想用它们的名称(即和 )替换列表中所有有空格后跟数字( 和)vlc 2.2
的字符串。这是输入字典:ado 3.4
ultr 3.1
vlc
ado
ultr
input = {'cl1': {'to_do': ['ab',
'dir8',
'cop',
'vlc 2.2.2.0',
'7zi',
'7zi',
'ado 3.4']},
'cl2': {'to_do': ['ultr 3.1', 'ab']}}
Run Code Online (Sandbox Code Playgroud)
这应该是输出:
result = {'cl1': {'to_do': ['ab',
'dir8',
'cop',
'vlc',
'7zi',
'7zi',
'ado']},
'cl2': {'to_do': ['ultr', 'ab']}}
Run Code Online (Sandbox Code Playgroud)
我正在尝试类似的事情:
for k in input:
for e in input[k]['to_do']:
input[k]['to_do'] = e.replace(e, e.split()[0])
Run Code Online (Sandbox Code Playgroud)
得到错误的输出:
{'cl1': {'to_do': 'ado'}, 'cl2': {'to_do': 'ab'}}
Run Code Online (Sandbox Code Playgroud)
我完全不明白错误在哪里。有什么帮助吗?谢谢
我有两个包含数字列表的列表(m1和m2).我正在尝试进行元素乘法和求和,包括交叉乘积以获得最终列表(结果),如下所示:
m1 = [[1, 2, 3], [4, 5, 6]]
m2 = [[7, 9, 2], [8, 1, 3]]
[[1*7+2*9+3*2,1*8+2*1+3*3],[4*7+5*9+6*2,4*8+5*1+6*3]]
result = [[31,19],[85,55]]
Run Code Online (Sandbox Code Playgroud) 我有一个numpy数组(a):
array([[ 1. , 5.1, 3.5, 1.4, 0.2],
[ 1. , 4.9, 3. , 1.4, 0.2],
[ 2. , 4.7, 3.2, 1.3, 0.2],
[ 2. , 4.6, 3.1, 1.5, 0.2]])
Run Code Online (Sandbox Code Playgroud)
我想在我的numpy数组的第一列创建一个prandas dataframe(pd),其中values = a,columns = A,B,C,D和index =,最后它应该如下所示:
A B C D
1 5.1 3.5 1.4 0.2
1 4.9 3.0 1.4 0.2
2 4.7 3.2 1.3 0.2
2 4.6 3.1 1.5 0.2
Run Code Online (Sandbox Code Playgroud)
我在尝试这个:
df = pd.DataFrame(a, index=a[:,0], columns=['A', 'B','C','D'])
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
ValueError: Shape of passed values is (5, 4), indices imply (4, …
Run Code Online (Sandbox Code Playgroud) 我有一个字符串列表,如下所示:
li1 = ['pin 2.3','vlo 5.4', 'lu 1.3', '3 packages installed', '', 'bla']
l12 = ['pin 2.3','vlo 5.4', '2 packages installed', 'bla', 'bla']
Run Code Online (Sandbox Code Playgroud)
我想从列表中过滤掉字符串'x packages installed'以及后面的字符串:
out1 = ['pin 2.3','vlo 5.4', 'lu 1.3']
out2 = ['pin 2.3','vlo 5.4']
Run Code Online (Sandbox Code Playgroud)
我怎么能用列表理解呢?谢谢
python ×5
list ×2
numpy ×2
ansible ×1
chocolatey ×1
dictionary ×1
fetch ×1
pandas ×1
powershell ×1
windows ×1