小编use*_*828的帖子

按短号拆分列表

我正在使用NumPy在图表上查找交叉点,但isClose每个交点返回多个值

所以,我打算尝试找到他们的平均值.但首先,我想隔离相似的值.这也是我觉得有用的技巧.

我有一个交叉点的x值列表idx,看起来像这样

[-8.67735471 -8.63727455 -8.59719439 -5.5511022  -5.51102204 -5.47094188
 -5.43086172 -2.4248497  -2.38476954 -2.34468938 -2.30460922  0.74148297
  0.78156313  0.82164329  3.86773547  3.90781563  3.94789579  3.98797595
  7.03406814  7.0741483   7.11422846]
Run Code Online (Sandbox Code Playgroud)

我想把它分成每个由相似数字组成的列表.

这是我到目前为止:

n = 0
for i in range(len(idx)):
    try:
        if (idx[n]-idx[n-1])<0.5:
            sdx.append(idx[n-1])
        else:
            print(sdx)
            sdx = []
    except:
        sdx.append(idx[n-1])
    n = n+1
Run Code Online (Sandbox Code Playgroud)

它在很大程度上起作用,但它会忘记一些数字:

[-8.6773547094188377, -8.6372745490981959]
[-5.5511022044088181, -5.5110220440881763, -5.4709418837675354]
[-2.4248496993987976, -2.3847695390781567, -2.3446893787575149]
[0.7414829659318638, 0.78156312625250379]
[3.8677354709418825, 3.9078156312625243, 3.9478957915831661]
Run Code Online (Sandbox Code Playgroud)

这可能是一种更有效的方法,有人知道吗?

python split numpy python-3.x

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

从列表中获取一定长度的字符串

我所追求的是这样的:

list1 = ["well", "455", "antifederalist", "mooooooo"]
Run Code Online (Sandbox Code Playgroud)

"455"由于字符数量而从列表中拉出的东西.

python string list

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

Scipy:尝试写入 wav 文件,AttributeError:'list' 对象没有属性 'dtype'

我正在使用 Anaconda3 和 SciPy 尝试使用数组编写 wav 文件:

wavfile.write("/Users/Me/Desktop/C.wav", 1000, array)

(我不知道每秒有多少个样本,我打算玩这个,但是我打赌是 1000)

array 返回一个包含 3000 个整数的数组,因此该文件将持续 3 秒。

但是,它在尝试运行时给了我这个错误:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-21-ce3a8d3e4b4b> in <module>()
----> 1 wavfile.write("/Users/Me/Desktop/C.wav", 1000, fin)

/Users/Me/anaconda/lib/python3.4/site-packages/scipy/io/wavfile.py in write(filename, rate, data)
213 
214     try:
--> 215         dkind = data.dtype.kind
216         if not (dkind == 'i' or dkind == 'f' or (dkind == 'u' and data.dtype.itemsize == 1)):
217             raise ValueError("Unsupported data type '%s'" %         data.dtype)

AttributeError: 'list' object has no attribute 'dtype'
Run Code Online (Sandbox Code Playgroud)

python arrays audio scipy anaconda

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

对于python 3,matplotlib中的曲线不连续

这是我绘制函数的程序,效果很好.只有一个问题.

while 1==1:
    import numpy as np
    import matplotlib.pyplot as plt
    print("FUNCTION GRAPHER")
    def graph(formula,domain):
        x = np.array(domain)
        y = eval(formula)
        plt.plot(x, y)
        plt.show()
    def sin(x):
        return np.sin(x)
    def cos(x):
        return np.cos(x)
    def tan(x):
        return np.tan(x)
    def csc(x):
        return 1/(np.sin(x))
    def sec(x):
        return 1/(np.cos(x))
    def cot(x):
        return 1/(np.tan(x))
    formula=input("Function: y=")
    domainmin=int(input("Min X Value: "))
    domainmax=int(input("Max X Value: "))
    graph(formula, range(domainmin,domainmax))
    print("DONE!")
Run Code Online (Sandbox Code Playgroud)

当我尝试非线性函数时,它不是"曲线":

FUNCTION GRAPHER
Function: y=sin(x**2)
Min X Value: 0
Max X Value: 32
Run Code Online (Sandbox Code Playgroud)

我不能张贴一张照片,因为我还没有足够的声望......但它只是非常尖刻,并且每1个单位只绘制一个点数.

python matplotlib

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

Opening Images from URL using Pillow and urllib?

This is my "Image Pasting" Program, which is designed to take one image (here named product) and paste it over another image (here named background). Before, I simply had the program get images from my computer. But I decided to add another feature where you can get them from a url. The computer part still works great.

from PIL import Image, ImageFilter
import urllib.request,io
print("ALL IMAGES MUST BE PNG FORMAT")
ext=input("Get Image From Computer or Internet?(c or i)")
if ext …
Run Code Online (Sandbox Code Playgroud)

python url urllib pillow

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

标签 统计

python ×5

anaconda ×1

arrays ×1

audio ×1

list ×1

matplotlib ×1

numpy ×1

pillow ×1

python-3.x ×1

scipy ×1

split ×1

string ×1

url ×1

urllib ×1