我正在使用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)
这可能是一种更有效的方法,有人知道吗?
我所追求的是这样的:
list1 = ["well", "455", "antifederalist", "mooooooo"]
Run Code Online (Sandbox Code Playgroud)
"455"由于字符数量而从列表中拉出的东西.
我正在使用 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) 这是我绘制函数的程序,效果很好.只有一个问题.
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个单位只绘制一个点数.
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)