我们如何从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中连接对象吗? 现在我不认为这是可能的......
在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) 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) 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) 当我在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) 如何分叉我自己的 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) 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?
我想看看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 中最大公约数的代码
我是机器学习初学者.我想通过教电脑玩跳棋来学习基础知识.实际上,我想要学习的游戏是Domineering和Hex.我选择的语言是Python
这些游戏很容易存储,规则比国际象棋简单得多,但玩的人不多.如果我能够实现这个想法,那么试验组合博弈论来查看计算机是否能找到最佳动作将会很棒.
我从IBM的一个人那里发现了这篇关于20 世纪60年代的跳棋的旧论文.最初我曾问过神经网络,但他们说这是错误的工具.
编辑:可能是机器学习不是正确的策略.在那种情况下,出了什么问题?什么是更好的方式?
我通过堆栈安装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)