在Babel 5.x中,我可以编写以下代码:
app.js
export default function (){}
Run Code Online (Sandbox Code Playgroud)
index.js
require('babel/register');
require('./app')();
Run Code Online (Sandbox Code Playgroud)
然后,我可以运行node index.js没有错误.但是,使用Babel 6.x,运行以下代码
index.es6.js
require('babel-core/register');
require('./app')();
Run Code Online (Sandbox Code Playgroud)
导致错误
require(...)不是函数
我想知道为什么?
在Javascript中观察数组中的更改是相对微不足道的.
我使用的一种方法是这样的:
// subscribe to add, update, delete, and splice changes
Array.observe(viewHelpFiles, function(changes) {
// handle changes... in this case, we'll just log them
changes.forEach(function(change) {
console.log(Object.keys(change).reduce(function(p, c) {
if (c !== "object" && c in change) {
p.push(c + ": " + JSON.stringify(change[c]));
}
return p;
}, []).join(", "));
});
});
Run Code Online (Sandbox Code Playgroud)
但是,我最近读过的Array.observe是不推荐使用的,我们应该使用代理对象.
我们如何检测Proxy对象中数组的变化?我无法找到任何有兴趣详述的例子吗?
我有一个图表,从标记太大的df.plot(style="o")地方创建o.是否有可能将它们缩小?
import pandas as pd
df = pd.DataFrame(range(1, 10))
df.plot(style="o")
Run Code Online (Sandbox Code Playgroud)
我怎样才能缩小它们?
我正在尝试使用fetch和ES6 promises智能地处理来自API的成功/错误响应.
以下是我需要处理响应状态的方法:
204: has no json response, but need to treat as success
406: should redirect to sign in
422: has json for error message
< 400 (but not 204): success, will have json
>= 400 (but not 422): error, will not have json
Run Code Online (Sandbox Code Playgroud)
所以,我正在努力学习如何干净利落地写这个.
我现在有一些不太常用的代码,看起来像这样:
fetch()
.then(response => checkStatus(response))
.then(parseJSON) //will throw for the 204
.then(data => notify('success', someMsg))
.catch(error => checkErrorStatus(error))
.then(parseJSON)
.then(data => notify('error', dataForMsg)
.catch(error => notify('error', someGenericErrorMsg)
Run Code Online (Sandbox Code Playgroud)
但是使用catch两次似乎很奇怪,我还不知道如何处理204.
另外,只是澄清checkStatus并checkErrorStatus做类似的事情:
export …Run Code Online (Sandbox Code Playgroud) 我是新来的代码文档,并试图用grunt-ngdocs记录我的角度应用程序.
我从以下网址克隆了一个工作示例:https://github.com/m7r/grunt-ngdocs-example
给定的示例缺少文档控制器,因此我使用以下代码添加了自己的文档控制器:
/**
* @ngdoc controller
* @name rfx.controller:testCtrl
* @description
* Description of controller.
*/
.controller('testCtrl', function() {
});
Run Code Online (Sandbox Code Playgroud)
当我尝试通过从命令行运行grunt来构建文档时,我收到以下错误消息:
Warning: Don't know how to format @ngdoc: controller Use --force to continue.
Run Code Online (Sandbox Code Playgroud)
我该如何解决?我阅读了本指南http://www.shristitechlabs.com/adding-automatic-documentation-for-angularjs-apps/,如果我尝试记录控制器,我无法弄清楚为什么我会不断收到错误消息:(谢谢任何帮助!
javascript documentation-generation angularjs ngdoc grunt-ngdocs
我正在上网学习python,讲师告诉我们链式索引不是一个好主意.但是,他没有说出是适当的替代方案.
假设我有一个Pandas数据框,其中行索引为['1', '2', '3'],列为名称['a', 'b', 'c'].
使用命令df['1']['a']提取第一行和第一列中找到的值的适当替代方法是什么?
有没有一种方法可以将带有n级索引的DataFrame 转换为n- D Numpy数组(又名n -tensor)?
假设我设置了一个像DataFrame
from pandas import DataFrame, MultiIndex
index = range(2), range(3)
value = range(2 * 3)
frame = DataFrame(value, columns=['value'],
index=MultiIndex.from_product(index)).drop((1, 0))
print frame
Run Code Online (Sandbox Code Playgroud)
哪个输出
value
0 0 0
1 1
2 3
1 1 5
2 6
Run Code Online (Sandbox Code Playgroud)
该索引是一个2级分层索引.我可以使用数据从数据中提取二维Numpy数组
print frame.unstack().values
Run Code Online (Sandbox Code Playgroud)
哪个输出
[[ 0. 1. 2.]
[ nan 4. 5.]]
Run Code Online (Sandbox Code Playgroud)
这如何推广到n级索引?
玩unstack(),似乎它只能用于按摩DataFrame的二维形状,但不能用于添加轴.
我不能使用eg frame.values.reshape(x, y, z),因为这将要求帧包含确切的x * y * z行,这是无法保证的.这是我试图drop()在上面的例子中通过一行来证明的.
任何建议都非常感谢.
我正在训练一个神经网络,它有10个左右的分类输入.在对这些分类输入进行一次热编码后,我最终将大约500个输入馈入网络.
我希望能够确定每个分类输入的重要性.Scikit-learn有许多特征重要性算法,但是这些算法中的任何一个都可以应用于分类数据输入吗?所有示例都使用数字输入.
我可以将这些方法应用于单热编码输入,但是在应用二进制输入后如何提取含义?如何判断分类输入的特征重要性?
python algorithm machine-learning neural-network scikit-learn
我有以下几点np.array:
my_matrix = np.array([[1,np.nan,3], [np.nan,1,2], [np.nan,1,2]])
Run Code Online (Sandbox Code Playgroud)
my_matrix = np.array([[1,np.nan,3], [np.nan,1,2], [np.nan,1,2]])
Run Code Online (Sandbox Code Playgroud)
如果我对其进行评估np.cov,我会得到:
np.cov(my_matrix)
Run Code Online (Sandbox Code Playgroud)
array([[ 1., nan, 3.],
[nan, 1., 2.],
[nan, 1., 2.]])
Run Code Online (Sandbox Code Playgroud)
但是如果我用它来计算它,pd.DataFrame.cov我会得到不同的结果:
pd.DataFrame(my_matrix).cov()
Run Code Online (Sandbox Code Playgroud)
np.cov(my_matrix)
Run Code Online (Sandbox Code Playgroud)
我知道根据pandas文档,他们处理nan值。
我的问题是,我怎样才能得到相同(或相似的结果)numpy?或者在计算协方差时如何处理丢失的数据numpy?
到目前为止,我一直在使用Pyramid从python包中的文件夹中提供静态资源,如文档中所述:
config.add_static_view('static', 'myapp:static')
Run Code Online (Sandbox Code Playgroud)
并从模板加载它们如下:
<script type="text/javascript" src="{{ request.application_url }}/static/js/jquery-1.7.1.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
但是,我注意到Chrome会发出如下警告:
Resource interpreted as Stylesheet but transferred with MIME type apache/2.2.14: "http://mydomain.com/static/js/jquery-1.7.1.min.js"
Run Code Online (Sandbox Code Playgroud)
要么
Resource interpreted as Stylesheet but transferred with MIME type text/plain: "http://mydomain.com/static/js/jquery-1.7.1.min.js"
Run Code Online (Sandbox Code Playgroud)
这在硬刷新时发生,并且似乎在3-4中随机资源加载<head>了错误的Content-Type标头(根据Pyramid文档,标头由文件扩展名确定).
我没有能够推断出如何设置错误标头的模式.有时,它适用text/plain于javascript/CSS文件,有时它是一个类似的路径/static/js/something.js(并且此路径与请求URL无关),有时它是Server标题的值,apache/2.2.14如上所述.
这是一个很大的问题,因为当返回带有错误内容类型的CSS时,它不会被渲染,这会破坏整个页面.我通过捕获/staticApache的请求,并使用它来提供静态资产,同时让所有其他请求通过金字塔来解决这个问题.我不再在Chrome中看到错误的MIME类型警告.但是,我想知道是否有人遇到过这个问题,以及它是否是金字塔错误,或者我是否在做其他错误.
编辑:我忘了提供我如何部署我的应用程序的规格.生产服务器运行Apache 2.2,应用程序在mod_wsgi下运行.我遵循的过程几乎是本教程中逐字描述的:http://docs.pylonsproject.org/projects/pyramid/en/1.0-branch/tutorials/modwsgi/index.html.重要提示:只有通过mod_wsgi在Apache上运行时才会出现此问题.当我在服务员本地运行应用程序时,Content-Type标头始终是正确的.
python ×6
javascript ×4
pandas ×4
ecmascript-6 ×2
algorithm ×1
angularjs ×1
babeljs ×1
chain ×1
covariance ×1
es6-promise ×1
fetch-api ×1
grunt-ngdocs ×1
indexing ×1
matplotlib ×1
mod-wsgi ×1
multi-index ×1
ngdoc ×1
numpy ×1
promise ×1
pyramid ×1
python-3.x ×1
scikit-learn ×1
wsgi ×1