小编joh*_*ual的帖子

如何访问Elm中的图像数据?

我们如何从Elm中的图像中获取Pixel数据?


在JavaScript中,是获取图中一组像素颜色的代码(取自此处)

var image = new Image;
image.src = "starry-night.jpg";

var canvas  = d3.select("body").append("canvas");
var context = canvas.node().getContext("2d");

context.drawImage(image, 0, 0);

// beware variable name "image" got used twice
image = context.getImageData(0, 0, width, height);

var x = Math.random()*width,
    y = Math.random()*height,
    i = (y * width + x) << 2;

pixelColor = d3.rgb(image.data[i + 0], image.data[i + 1], image.data[i + 2]) + "";
Run Code Online (Sandbox Code Playgroud)

代码将图像加载到<canvas>元素,然后使用画布从画布中提取像素的颜色image.getImageData().

我们可以image.data在Elm中连接对象吗? 现在我不认为这是可能的......

  • 现在Collage类型是表格列表......
  • HTML 也是一个可以将imags放入DOM的模块. …

javascript svg canvas elm

8
推荐指数
1
解决办法
691
查看次数

在jupyter笔记本中的cython

在Jupyter Notebook中加载Cython文件时出错.有任何想法吗?

%load_ext Cython

import numpy as np
cimport numpy as np
import cython
Run Code Online (Sandbox Code Playgroud)

只是一个简单的错误消息:

File "<ipython-input-3-7e39dc7f561b>", line 5
    cimport numpy as np
                ^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)

ipython cython jupyter-notebook

8
推荐指数
1
解决办法
4679
查看次数

setInterval() - 意外的标识符 - 但它可以工作一次

Uncaught SyntaxError: Unexpected identifier如果它能运作一次,为什么我会得到它?

StackOverflow上有很多这些.妙语通常是脚本中某处的拼写错误.

它工作一次,然后每秒发出1条错误信息.

我在这里改变地图上的状态颜色:

<!-- language: lang-js -->
<script type="text/javascript">
colors = [ 'rgba(255,0,0,0.1)','rgba(0,255,0,0.1)','rgba(0,0,255,0.1)'  ];

$(document).ready(function(){

    setInterval(
        $("ul").children().eq( Math.floor(50*Math.random())).css('color', colors[Math.floor(3*Math.random())] )
    ,1000);

});
</script>
Run Code Online (Sandbox Code Playgroud)

javascript jquery

7
推荐指数
1
解决办法
4913
查看次数

Facebook的react.js - 对象不是一个功能

Facebook的read.js教程,我收到此错误:

Uncaught TypeError: Property 'CommentList' of object [object Object] is not a function
Run Code Online (Sandbox Code Playgroud)

事实上,react.js自己的示例页面有:

Uncaught TypeError: object is not a function
Run Code Online (Sandbox Code Playgroud)

任何人都能解释正确的用法吗?


我在教程中的进步

导入以下两个javascripts:

http://fb.me/react-0.4.1.js http://fb.me/JSXTransformer-0.4.1.js

HTML是一行:

  <div id="content"></div>
Run Code Online (Sandbox Code Playgroud)

而javascript或者<script type="text/jsx"> 看起来像这样:

var CommentBox = React.createClass({
    render: function() {
        return (
           <div class="commentBox">
        <h1>Comments</h1>
        <CommentList />
        <CommentForm />
        </div>
        );
    }
});


React.renderComponent(
    <CommentBox />,
    document.getElementById('content')
);


var CommentList = React.createClass({
    render: function() {
        return (
        <div class="commentList">
        <Comment author="Pete Hunt">This is one comment</Comment> …
Run Code Online (Sandbox Code Playgroud)

javascript markdown frontend facebook reactjs

7
推荐指数
1
解决办法
1万
查看次数

数学指数函数的Python源代码?

当我在Python中进行数学计算时我们正在使用哪个库.例如

>>> 2**0.5
1.4142135623730951
Run Code Online (Sandbox Code Playgroud)

如何找到使用的源代码?这只是math.pow()功能吗?不幸的是,inspect.getsource(pow)返回一种错误.

在Github上搜索将其缩小到13个可能的文件.我并不完全了解cPython是如何构建的.

/*[clinic input]
math.pow
    x: double
    y: double
    /
Return x**y (x to the power of y).
[clinic start generated code]*/

static PyObject *
math_pow_impl(PyObject *module, double x, double y)
/*[clinic end generated code: output=fff93e65abccd6b0 input=c26f1f6075088bfd]*/
{
    double r;
    int odd_y;

    /* deal directly with IEEE specials, to cope with problems on various
       platforms whose semantics don't exactly match C99 */
    r = 0.; /* silence compiler warning */ …
Run Code Online (Sandbox Code Playgroud)

c math cpython python-2.7

7
推荐指数
1
解决办法
614
查看次数

如何在 GitHub 上 fork 自己的要点?

如何分叉我自己的 GitHub gist?

一种可能性:gist 上发布了一个脚本,但我不知道如何将其安装在我的 gitHub 上。在这种情况下,解释如何使用该脚本以及它正在做什么。

(重新)分叉任何要点,包括你自己的

<!-- language: lang-js -->
// ==UserScript==
// @name           (Re)fork any gist, including your own
// @namespace      https://github.com/johan
// @description    Adds a "fork" button to gists missing one at gist.github.com, so you can create multiple forks
// @match          https://gist.github.com/*
// @include        https://gist.github.com/*
// ==/UserScript==

if (/^\/\d+/.test(location.pathname) &&
    !document.querySelector('a img[alt="fork"]')) {
  var i = document.createElement('img')
    , a = document.createElement('a')
    , u = document.querySelector('img.button').src
    , p = document.querySelector('.title');

  a.title = 'Create another fork of this …
Run Code Online (Sandbox Code Playgroud)

javascript gist github

6
推荐指数
1
解决办法
1746
查看次数

stack ghc error"无效选项`--make`

我正在哈克塞尔学习哈基尔的图书馆.我需要跑

ghc --make site.hs
Run Code Online (Sandbox Code Playgroud)

不过,我instlled GHC与堆栈,所以我可以不再运行ghc,而是stack ghc

$ stack ghc --make site.hs
Invalid option `--make'
Run Code Online (Sandbox Code Playgroud)

我该怎么编译我的site.hs

haskell hakyll haskell-stack

6
推荐指数
1
解决办法
695
查看次数

str.split 的源代码?

我想看看str.split()在 Python 中是如何实现的这是我尝试过的:

> inspect.getsource(str.split)

TypeError: <method 'split' of 'str' objects> is not a module, 
class, method, function, traceback, frame, or code object
Run Code Online (Sandbox Code Playgroud)

复制 StackOverflow 上的另一个示例不起作用:Python 中最大公约数的代码

python python-2.7 python-internals

6
推荐指数
1
解决办法
7283
查看次数

机器学习用Python来玩跳棋?

我是机器学习初学者.我想通过教电脑玩跳棋来学习基础知识.实际上,我想要学习的游戏是DomineeringHex.我选择的语言是Python

这些游戏很容易存储,规则比国际象棋简单得多,但玩的人不多.如果我能够实现这个想法,那么试验组合博弈论来查看计算机是否能找到最佳动作将会很棒.

我从IBM的一个人那里发现了这篇关于20 世纪60年代的跳棋的旧论文.最初我曾问过神经网络,但他们说这是错误的工具.

编辑:可能是机器学习不是正确的策略.在那种情况下,出了什么问题?什么是更好的方式?

python machine-learning game-theory

5
推荐指数
1
解决办法
5888
查看次数

从堆栈安装ghcjs

我通过堆栈安装stack ghc -- --version了GHC (因此显示GHC-7.10.3)

$ stack install ghcjs

Run from outside a project, using implicit global project config
Using resolver: lts-5.2 from implicit global project's config file: /home/john/.stack/global-project/stack.yaml
The following target packages were not found: ghcjs
Run Code Online (Sandbox Code Playgroud)

一些资源建议ghcjs有点实验性(尽管在后续阶段).


看看http://docs.haskellstack.org/en/stable/ghcjs/我想也许我可以找到stack.yaml并改变它.

要使用堆栈> = 0.1.8的GHCJS,将GHCJS版本放在stack.yaml的编译器字段中......然后 stack setup

$ cat ~/.stack/global-project/stack.yaml
# This is the implicit global project's config file, which is only used when
# 'stack' is run outside of a real project.  Settings here …
Run Code Online (Sandbox Code Playgroud)

haskell ghcjs haskell-stack

5
推荐指数
1
解决办法
1170
查看次数