我正在尝试绘制图像的2D FFT:
from scipy import fftpack, ndimage
import matplotlib.pyplot as plt
image = ndimage.imread('image2.jpg', flatten=True) # flatten=True gives a greyscale image
fft2 = fftpack.fft2(image)
plt.imshow(fft2)
plt.show()
Run Code Online (Sandbox Code Playgroud)
但我明白了TypeError: Image data can not convert to float.
如何绘制图像的2D FFT?
假设我们有这个日期时间:
var d = new Date("Sat Jul 21 2018 14:00:00 GMT+0200");
Run Code Online (Sandbox Code Playgroud)
将其导出为字符串(console.log(d))会在浏览器之间产生不一致的结果:
Sat Jul 21 2018 14:00:00 GMT+0200 (Paris, Madrid (heure d’été)) 使用Chrome
Sat Jul 21 14:00:00 UTC+0200 2018 使用Internet Explorer等
因此我们不能将日期时间发送到格式不一致的服务器。
那么自然的想法是要求一个ISO8601日期时间,并使用d.toISOString();它,但它给出了UTC日期时间:2018-07-21T12:00:00.000Z而我想使用本地时区时间:
2018-07-21T14:00:00+0200
or
2018-07-21T14:00:00
Run Code Online (Sandbox Code Playgroud)
如何获得它(不依赖诸如momentjs之类的第三方依赖项)?
我尝试了一下,似乎可行,但是没有更自然的方法吗?
var d = new Date("Sat Jul 21 2018 14:00:00 GMT+0200");
Run Code Online (Sandbox Code Playgroud)
使用PyAudio(Portaudio绑定)和ASIO + DirectSound支持时,此代码:
import pyaudio
p = pyaudio.PyAudio()
for i in range(p.get_device_count()):
print p.get_device_info_by_index(i)
Run Code Online (Sandbox Code Playgroud)
...产生此错误:
UnicodeDecodeError: 'utf8' codec can't decode byte 0xe9 in position 1: invalid continuation byte
Run Code Online (Sandbox Code Playgroud)
我们怎样才能解决这个问题?
问题可能来自"pyaudio.py",第990行,因为utf8解码不成功:
return {'index' : index,
'structVersion' : device_info.structVersion,
'name' : device_info.name,
Run Code Online (Sandbox Code Playgroud)
这里的答案音频设备中的特殊字符名称:Pyaudio("不要使用PyAudio")并不令人满意.
追溯
...
{'defaultSampleRate': 44100.0, 'defaultLowOutputLatency': 0.0, 'defaultLowInputLatency': 0.12, 'maxInputChannels': 2L, 'structVersion': 2L, 'hostApi': 1L, 'index': 8, 'defaultHighOutputLatency': 0.0, 'maxOutputChannels': 0L, 'name': u'Microphone interne (Conexant 20672 SmartAudio HD)', 'defaultHighInputLatency': 0.24}
Traceback (most recent call last):
File "D:\test\test.py", line …Run Code Online (Sandbox Code Playgroud) 设L是一个列表L = [A_1, A_2, ..., A_n],每个A_i都是numpy.int32长度为1024的数组.
(大部分时间1000 <n <4000).
经过一些分析,我看到一个最耗时的操作是求和:
def summation():
# L is a global variable, modified outside of this function
b = numpy.zeros(1024, numpy.int32)
for a in L:
b += a
return b
Run Code Online (Sandbox Code Playgroud)
PS:我认为我不能定义大小的2D数组,1024 x n因为n它不是固定的:一些元素被动态删除/添加到L,因此len(L) = n在运行时可以在1000到4000之间变化.
使用Cython可以获得显着改善吗?如果是这样,我应该如何cython重新编码这个小函数(我不应该添加一些cdef打字?)
或者你能看到一些可能的其他改进吗?
在项目bigpicture.js/live demo中,我在缩放时替换每个元素(通过移动它们,并改变它们的字体大小).有用.
现在我想测试CSS的漂亮transform: scale(...);功能.
在以下测试中,我想:
<div id="container">用户点击时缩放整体.问题是无论我们点击哪里,缩放都以相同的方式完成. 如何缩放已被点击的点?(就像它已经与我目前的bigpicture.js实现一起工作).
var container = document.getElementById("container"), wrapper = document.getElementById("wrapper");
var zoom = 1;
wrapper.onclick = function (e) {
zoom *= e.ctrlKey ? 1/1.2 : 1.2;
container.style.transform = "scale(" + zoom + ")";
}Run Code Online (Sandbox Code Playgroud)
<style>
#wrapper { position:absolute; top:0px; left:0px; width:1000px; height:600px; background-color: #AAAABB; }
#container { position:absolute; top:100px; left:100px; width:600px; height:400px; background-color: grey; transition-duration: 0.3s; …Run Code Online (Sandbox Code Playgroud)在进行STFT时,然后使用库Librosa对16位44.1 khz音频文件进行反向STFT(iSTFT):
import librosa
y, sr = librosa.load('test.wav', mono=False)
y1 = y[0,]
S = librosa.core.stft(y1)
z1 = librosa.core.istft(S, dtype=y1.dtype)
librosa.output.write_wav('test2.wav', z1, sr)
Run Code Online (Sandbox Code Playgroud)
输出只是一个22千赫兹的音频文件.为什么?librosa的采样率变化在哪里?
我正在尝试使用(此处可运行代码)生成具有 15 种不同颜色的彩虹:
size(360,100);
colorMode(HSB, 360, 100, 100); // Hue in degrees in [0, 360],
// saturation/brightness in [0, 100]
// like in Photoshop
noStroke();
for (int i = 0; i < 15; i++)
{
fill(i*24, 100, 100); // 24*15 = 360
rect(i*24, 0, 25, 100);
}
Run Code Online (Sandbox Code Playgroud)
但它不会产生丰富的 15 种彩虹调色板,而是缺少一些颜色(例如鲜艳的黄色)。
是否有一种众所周知的算法可以产生生动的彩虹调色板?
我正在写一个玩具会议点/中继服务器,在端口5555上监听两个客户端"A"和"B".
它的工作原理如下:服务器从第一个连接的客户端A接收的每个字节都将被发送到第二个连接的客户端B,即使A和B不知道它们各自的IP:
A -----------> server <----------- B # they both connect the server first
A --"hello"--> server # A sends a message to server
server --"hello"--> B # the server sends the message to B
Run Code Online (Sandbox Code Playgroud)
此代码目前正在运行:
# server.py
import socket, time
from threading import Thread
socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.bind(('', 5555))
socket.listen(5)
buf = ''
i = 0
def handler(client, i):
global buf
print 'Hello!', client, i
if i == 0: # client A, who sends data to …Run Code Online (Sandbox Code Playgroud) 在这里,我们s在循环时修改字符串:
s = 'hello'
for c in s:
s += c
print(s)
Run Code Online (Sandbox Code Playgroud)
它不会产生无限循环(它可以:我们在每次迭代中添加一个新字符!)。
多年来我就知道这一点,但我无法真正解释原因。这与字符串不变性有关还是无关?
执行时for c in s:,是否s在开始循环之前将原件复制到内存中?
我认为可能会产生无限循环的另一种情况,但它不会:
s = 'hello'
def f(x):
i = 0
while True:
try:
yield x[i]
except IndexError:
break
i += 1
for c in f(s):
s += c
print(s)
Run Code Online (Sandbox Code Playgroud) Microsoft SmartScreen,以其消息而闻名:
Windows Defender SmartScreen 阻止无法识别的应用程序启动
对于最终用户避免恶意软件很有用,但也会伤害独立开发人员,因为当他们分发二进制文件时:最终用户会看到可怕的消息,这对开发人员的声誉来说是一个问题(请参阅某人的评论“我的客户经常认为我正在提供病毒、恶意软件或非法内容,他们告诉他们的朋友,我就失去了销售”):
尽管我签署了可执行文件,智能屏幕过滤器仍然抱怨,为什么?
即使使用付费证书,如果software-release1.0.1.exe最终被列入白名单,当您发布software-release1.0.2.exe更新时,消息将再次出现:
正在将 Microsoft SmartScreen 信誉转移到更新的证书
唯一的解决方案似乎是扩展“EV 代码签名”,每年可能需要 300-500 美元(这种固定费用使得小型独立开发商的税率更高)。
问题:有没有办法通过将 .exe 提交给 Microsoft 进行分析来立即(或几天)为所有用户(而不仅仅是在我自己的计算机上)将其列入白名单?
我看过这个链接: https: //www.microsoft.com/en-us/wdsi/filesubmission,有人能够成功使用它来避免进一步的 SmartScreen 警报吗?(好像没有)。
还有其他方法吗?比如通过自动化脚本自动部署100个虚拟机,并让每个虚拟机自动下载安装.exe?但这可能来自同一个IP,那么微软可能会将声誉计数器增加+1而不是+100?
python ×6
audio ×2
javascript ×2
arrays ×1
binding ×1
certificate ×1
code-signing ×1
colors ×1
css ×1
css3 ×1
cython ×1
date ×1
datetime ×1
fft ×1
hsb ×1
html ×1
immutability ×1
librosa ×1
loops ×1
matplotlib ×1
nat ×1
networking ×1
numpy ×1
portaudio ×1
processing ×1
profiling ×1
pyaudio ×1
rgb ×1
scipy ×1
smartscreen ×1
sockets ×1
string ×1
timezone ×1
transform ×1
windows ×1