我有以下课程:
public class people
{
public string name { get; set; }
public string hobby { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我想显示一个这样的列表:
no | name | hobby
-----------------------
01 | kim | tv
02 | kate | pc
03 | kim | tv
04 | kate | pc
Run Code Online (Sandbox Code Playgroud)
我知道要实现这一目标的唯一方法是将人们的阶级转变为
public class people
{
public string no{ get; set; }
public string name { get; set; }
public string hobby { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
并循环List<people>设置每个no属性。
有没有更好的方法来添加索引号列?
我想在进行特定的 ajax 调用时阻止当前页面,并使用 blockUI 作为消息框。我不能只用$(document).ajaxStart($.blockUI).ajaxStop($.unblockUI);
我的代码如下..
bc.find('.submit').click(function (e) {
e.preventDefault();
if ($(this).hasClass('lock'))
return;
$.blockUI();
$(this).addClass('lock');
bc.submit();
});
var validator;
validator = bc.validate({
ignore: '',
rules: {
UserName: {
required: true
}
},
messages: {
UserName: 'must have',
},
submitHandler: function (form) {
$.ajax({
url: '/yyyy/xxxx',
type: 'POST',
data: postdata,
complete: function () {
bc.find('.submit').removeClass('lock');
},
success: function (data) {
if (data.status == 'OK') {
$.blockUI({ message: 'OK' });
......
}
else {
switch (data.status) {
case 'xxx':
......
} …Run Code Online (Sandbox Code Playgroud) 当我使用django时:我总是这样做
return HttpResponse(json.dumps(result), mimetype='application/json')
Run Code Online (Sandbox Code Playgroud)
怎么能扭曲呢?官方文件不说这个.
文件在这里
只能Serving WSGI Applications设置mimetype.但我想处理GET和POST没有更多的例子,我搜索没有找到.
from twisted.web import resource
class MyGreatResource(resource.Resource):
def render_GET(self, request):
return "xxxx"
Run Code Online (Sandbox Code Playgroud)
它返回原始字符串
我希望我的app组件有一个默认道具,并使用该道具 mapStateToProps.
import React, { Component, PropTypes } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import Footer from '../components/Footer';
import TreeNode from '../containers/TreeNode';
import Home from '../containers/Home';
import * as NodeActions from '../actions/NodeActions'
export default class App extends Component {
constructor(props, context) {
super(props, context)
this.props = {
info:{
path:'/'
}
}
}
componentWillMount() {
// this will update the nodes on state
this.props.actions.openNode('/');
}
render() {
const { node …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用2D CNN对中文文章进行文本分类,并且遇到了一些问题Convolution2D.我知道Convolution2D应对图像的基本流程,但通过使用我的数据集与keras卡住了.这是我的一个问题:
9800中文文章.
负面文章和非负面文章[请注意它可能是正面的或中立的],只是一个二元分类问题.我对Convolution1DNN 进行了测试,结果并不好.
使用tokenizer和word2vec转换为形状(9800, 6810, 200).
最长的文章有6810个单词,最短文章少了50个字,需要填充所有文章到6810,200个是word2vec大小(似乎有人称之为embedding_size?).格式如:
1 [[word2vec size=200], [word2vec size=200], [word2vec size=200], [word2vec size=200], [word2vec size=200], [word2vec size=200]]
2 [[word2vec size=200], [word2vec size=200], [word2vec size=200], [word2vec size=200], [word2vec size=200], [word2vec size=200]]
....
9999 [[word2vec size=200], [word2vec size=200], [word2vec size=200], [word2vec size=200], [word2vec size=200], [word2vec size=200]]
Run Code Online (Sandbox Code Playgroud)这篇文章最大.字长6810太大了?我必须将9800个样本减少到6500以避免a MemoryError,因为6500已经吃掉了我所有的32GB内存.有什么方法可以优化内存使用量,除了将所有文章修剪成更短的长度?
我使用命令./plugin -i medcl/elasticsearch-analysis-ik/1.2.6来安装插件
但是我得到了
Error while installing plugin, reason:IllegalArgumentException: Plugin installation assumed to be site plugin, but contains source code, aborting installation.
一些搜索后,有人说我应该构建插件源代码.
但我不熟悉JAVA,官方文件即使IK Analysis Plugin (by Medcl)列表下也不说这个Supported by the community.如何构建源代码以及将编译文件放在何处?
我正在尝试使机器学习库与 scipy 稀疏矩阵一起工作。
下面的代码是检测是否有y1个以上的class。因为在做分类的时候如果只有1个class是没有意义的。
import numpy as np
y = np.array([0,1,0,1,0,1])
uniques = set(y) # get {0, 1}
if len(uniques) == 1:
raise RuntimeError("Only one class detected, aborting...")
Run Code Online (Sandbox Code Playgroud)
但set(y)如果y是 scipy 稀疏矩阵,则不起作用。
如果y是 scipy 稀疏矩阵,如何有效地获取所有唯一值?
PS:我知道set(y.todense())可能有用,但内存消耗太大
更新:
>>> y = sp.csr_matrix(np.array([0,1,0,1,0,1]))
>>> set(y.data)
{1}
>>> y.data
array([1, 1, 1])
Run Code Online (Sandbox Code Playgroud) 我正在制作一个基于react-redux的文件管理器应用程序,我遇到了问题input.
例如,我的代码:
PathForm.js:
export default class PathForm extends Component {
render() {
const { currentPath, handleSubmit } = this.props;
console.log('PathFormPathFormPathForm', this.props)
return (
<div className="path-box">
<form onSubmit={handleSubmit}>
<div>
<input type="text" className="current-path-input" placeholder="input path" value={currentPath} />
</div>
<button className="go-btn" type="submit">Go</button>
</form>
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
Explorer.js:
class Explorer extends Component {
goPath(e) {
e.preventDefault()
// fake function here, because I have to solve the input problem first
console.log('PathForm goPath:',this.props)
let {targetPath , actions} = this.props
swal(targetPath)
}
render() { …Run Code Online (Sandbox Code Playgroud) /src/styles/main.scss
@import 'materialize/sass/materialize.scss';
....
Run Code Online (Sandbox Code Playgroud)
我也试着@import './materialize/sass/materialize.scss';在这里工作.
它只在我在index.js中导入lib时才有效
/src/index.js(这有效)
import './styles/reset.css';
import './styles/main.scss';
import './styles/font-awesome/font-awesome.scss';
Run Code Online (Sandbox Code Playgroud)
webpack loader:
loaders: [
{
test: /\.js?/,
exclude: [/node_modules/, /styles/],
loaders: ['babel'],
include: path.join(__dirname, 'src')
},
{
test: /\.scss$/,
loader: 'style!css!sass'
},
{
test: /\.css$/,
loader: "style-loader!css-loader"
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url-loader?limit=10000&mimetype=application/font-woff'
},
{
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader'
}
Run Code Online (Sandbox Code Playgroud)
]
但得到错误:
ERROR in ./~/css-loader!./~/sass-loader!./src/styles/main.scss
Module not found: Error: Cannot resolve 'file' or 'directory' ../fonts/roboto/Roboto-Thin.eot in E:\Project\simple-redux
-boilerplate\src\styles
@ ./~/css-loader!./~/sass-loader!./src/styles/main.scss 6:73945-73987 6:74010-74052
ERROR …Run Code Online (Sandbox Code Playgroud) 我正在使用requestslib 从网站下载一些图像。
我的代码会在下载后检查文件大小。
示例代码:
def download(url, store_dir):
r = requests.get(url, headers=headers, proxies=proxies)
filename = r.headers.get('content-disposition').split('=')[1]
real_length = int(r.headers.get('content-length'))
wholepath = os.path.join(store_dir, filename)
with open(wholepath, 'wb') as f:
f.write(r.content)
f.close()
if os.path.getsize(wholepath) != real_length:
print('size error')
print('status_code: %s' %r.status_code)
print('headers: %s' %r.headers)
print('url"%s' % url)
print('orgin:', r.headers['content-length'], 'now',os.path.getsize(wholepath))
self.download(url, store_dir)
Run Code Online (Sandbox Code Playgroud)
但我通常会发现即使os.path.getsize(wholepath) == real_length.
我怎么解决这个问题?