是否有便捷/简便的方法来遍历数组上的for循环,同时获取值和索引?
基本选项:
i = 1
for file in ["foo.csv", "bar.csv"]
...
i += 1
end
Run Code Online (Sandbox Code Playgroud)
files = ["foo.csv", "bar.csv"]
for i in 1:length(files)
files[i]
end
Run Code Online (Sandbox Code Playgroud) 我有一个包含plot.ly图的页面,我想要将数据写入几次,覆盖之前的内容.
我找不到从plotly.js图中删除所有痕迹的方法,只是重新绘制添加数据而不删除旧的.
以下是崩溃我的Julia内核.有没有更好的方法来读取和解析大型(> 400 MB)JSON文件?
using JSON
data = JSON.parsefile("file.json")
Run Code Online (Sandbox Code Playgroud) 我想要来自 AVCaptureVideoDataOutput 的提要中整个图像的平均像素值,我目前正在捕捉图像并循环遍历像素以求和它们。
我想知道是否有更有效的方法来使用 GPU/openGL 来做到这一点,因为这是一个可并行化的图像处理任务。(也许是严重的高斯模糊,并读取中心像素值?)
一个特定要求是获得高精度结果,利用高水平的平均。请注意下面的 CGFloat 结果。
编辑:添加了 CIAreaAverage 的实现,如下面 Simon 的建议。它由useGPUbool分隔。
func captureOutput(captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, fromConnection connection: AVCaptureConnection!) {
var redmean:CGFloat = 0.0;
var greenmean:CGFloat = 0.0;
var bluemean:CGFloat = 0.0;
if (useGPU) {
let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)
let cameraImage = CIImage(CVPixelBuffer: pixelBuffer!)
let filter = CIFilter(name: "CIAreaAverage")
filter!.setValue(cameraImage, forKey: kCIInputImageKey)
let outputImage = filter!.valueForKey(kCIOutputImageKey) as! CIImage!
let ctx = CIContext(options:nil)
let cgImage = ctx.createCGImage(outputImage, fromRect:outputImage.extent)
let rawData:NSData = …Run Code Online (Sandbox Code Playgroud) thing从这里的子模块中导出所有方法的正确方法是什么(这不起作用):
module Foo
module Bar
thing(x::String) = 1
end
import .Bar: thing
module Baz
thing(x::Int) = 1
end
import .Baz: thing
export thing
end
Run Code Online (Sandbox Code Playgroud) 对大型矩阵进行索引似乎比FAR更长,0.5和0.6比0.4.7更长.
例如:
x = rand(10,10,100,4,4,1000) #Dummy array
tic()
r = squeeze(mean(x[:,:,1:80,:,:,56:800],(1,2,3,4,5)),(1,2,3,4,5))
toc()
Run Code Online (Sandbox Code Playgroud)
朱莉娅0.5.0 - >经过时间:176.357068283秒
Julia 0.4.7 - >经过时间:1.19991952秒
编辑:根据要求,我已更新基准使用BenchmarkTools.jl并将代码包装在函数中:
using BenchmarkTools
function testf(x)
r = squeeze(mean(x[:,:,1:80,:,:,56:800],(1,2,3,4,5)),(1,2,3,4,5));
end
x = rand(10,10,100,4,4,1000) #Dummy array
@benchmark testf(x)
Run Code Online (Sandbox Code Playgroud)
在0.5.0中,我得到以下内容(内存使用量很大):
BenchmarkTools.Trial:
samples: 1
evals/sample: 1
time tolerance: 5.00%
memory tolerance: 1.00%
memory estimate: 23.36 gb
allocs estimate: 1043200022
minimum time: 177.94 s (1.34% GC)
median time: 177.94 s (1.34% GC)
mean time: 177.94 s (1.34% GC)
maximum time: 177.94 s (1.34% GC) …Run Code Online (Sandbox Code Playgroud)