小编b10*_*ard的帖子

当鼠标悬停在线上时,flotr显示数据系列名称

我正在使用flotr来绘制90个数据集.平均而言,90组数据中只有两组实际上会生成一条潦草线.另外88个左右的y值会很低,以至于它们几乎不会在x轴上方达到峰值.这是一个例子......

在此输入图像描述

我的问题是我不知道这两行是什么数据集.我可以创造一个传奇,但这个传说将是巨大的,因为有大约90个数据集.所以我想知道当鼠标悬停在该数据集的图形数据上时,flotr是否具有标记这些数据集的功能.这样的功能存在吗?谢谢.

javascript flot flotr

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

为什么要将此字节数组初始化为1024

我是Java的新手,我正在尝试编写一个简单的Android应用程序.我的应用程序的assets文件夹中有一个大约3500行的大文本文件,我需要将其读入字符串.我找到了一个关于如何做到这一点的一个很好的例子但是我有一个关于为什么字节数组被初始化为1024的问题.我不想将它初始化为我的文本文件的长度吗?另外,我不想使用char,不是byte吗?这是代码:

private void populateArray(){
    AssetManager assetManager = getAssets();
    InputStream inputStream = null;
    try {
        inputStream = assetManager.open("3500LineTextFile.txt");
    } catch (IOException e) {
        Log.e("IOException populateArray", e.getMessage());
    }
    String s = readTextFile(inputStream);
    // Add more code here to populate array from string
}

private String readTextFile(InputStream inputStream) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    inputStream.length
    byte buf[] = new byte[1024];
    int len;
    try {
        while ((len = inputStream.read(buf)) != -1) {
            outputStream.write(buf, 0, len);
        }
        outputStream.close();
        inputStream.close();
    } catch …
Run Code Online (Sandbox Code Playgroud)

java android

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

如何阻止 numpy meshgrid 将默认数据类型设置为 int64

我必须使用 numpy meshgrid 创建一个非常大的网格。为了节省内存,我使用 int8 作为我尝试网格化的数组的数据类型。然而,meshgrid 不断将类型更改为 int64,这会占用大量内存。这是问题的一个简单示例......

import numpy

grids = [numpy.arange(1, 4, dtype=numpy.int8), numpy.arange(1, 5, dtype=numpy.int8)]

print grids
print grids[0].dtype, grids[0].nbytes

x1, y1 = numpy.meshgrid(*grids)

print x1.dtype, x1.nbytes
Run Code Online (Sandbox Code Playgroud)

该脚本打印

[array([1, 2, 3], dtype=int8), array([1, 2, 3, 4], dtype=int8)]

int8 3

int64 96
Run Code Online (Sandbox Code Playgroud)

为什么网格要这样做?有什么办法可以阻止它吗?我需要创建一个巨大的数组,因此我无法使用网格网格,除非我可以控制输出的数据类型。这是预期的行为还是一个麻木的错误?我在 numpy 中使用的所有其他函数都保留数据类型或允许您使用 dtype 参数更改它。meshgrid 函数似乎不允许这样做。

python numpy scipy

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

如何从表单中获取文件内容?

如何从HTML表单中获取文件的内容?这是我正在使用的一个例子.所有它输出的东西像"C:\ Fake Path \nameoffile

<html>
<head>

<script type="text/javascript">
    function doSomething(){
        var fileContents = document.getElementById('idexample').value;
        document.getElementById('outputDiv').innerHTML = fileContents;
    }
</script>

</head>
<body >

<form name = "form_input" enctype="multipart/form-data">

<input type="file" name="whocares" id="idexample" />
<button type="button" onclick="doSomething()">Enter</button>

</form>

<div id="outputDiv"></div>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

编辑:似乎解决方案很难以这种方式实现.我想要完成的是将文件发送到我的网络服务器上的python脚本.这是我第一次尝试这种事情,所以欢迎提出建议.我想我可以将python脚本放在我的cgi文件夹中并使用类似的东西将值传递给它

/cgi/pythonscript.py?FILE_OBJECT=fileobjecthere&OTHER_VARIABLES=whatever
Run Code Online (Sandbox Code Playgroud)

这是将文件内容发送到网络服务器而不是让javacript直接使用FileReader打开它的更好的解决方案吗?

html javascript

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

用 sklearn GMM 计算概率

我想确定一个数据点属于一组数据的概率。我读到 sklearn GMM 可以做到这一点。我尝试了以下....

import numpy as np
from sklearn.mixture import GMM

training_data = np.hstack((
    np.random.normal(500, 100, 2000).reshape(-1, 1),
    np.random.normal(500, 100, 2000).reshape(-1, 1),
))

# train the classifier and get max score
g = GMM(n_components=1)
g.fit(training_data)
scores = g.score(training_data)
max_score = np.amax(scores)

# create a candidate data point and calculate the probability
# it belongs to the training population
candidate_data = np.array([[490, 450]])
candidate_score = g.score(candidate_data)
Run Code Online (Sandbox Code Playgroud)

从这一点开始,我不知道该怎么做。我读到我必须对对数概率进行归一化,以获得属于一个群体的候选数据点的概率。会不会是这样的……

candidate_probability = (np.exp(candidate_score)/np.exp(max_score)) * 100

print candidate_probability
>>> [ 87.81751913]
Run Code Online (Sandbox Code Playgroud)

这个数字似乎并不合理,但我真的超出了我的舒适区,所以我想我会问。谢谢!

python statistics gaussian scikit-learn

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

未来的功能还需要AssetManager吗?

我何时创建并关闭 AssetManager 实例。

我的程序中有一个错误。DDMS 说......

07-04 18:44:59.241: DEBUG/KeyguardViewMediator(65): pokeWakelock(5000)
07-04 18:44:59.541: DEBUG/KeyguardViewMediator(65): pokeWakelock(5000)
07-04 18:45:00.101: INFO/ARMAssembler(65): generated scanline__00000077:03545404_00000004_00000000 [ 47 ipp] (67 ins) at [0x33b540:0x33b64c] in 9815520 ns
07-04 18:45:00.281: INFO/ARMAssembler(65): generated scanline__00000177:03515104_00001001_00000000 [ 91 ipp] (114 ins) at [0x33c088:0x33c250] in 2206721 ns
07-04 18:45:00.561: WARN/ActivityManager(65): finishReceiver called but no pending broadcasts
07-04 18:45:10.843: DEBUG/AndroidRuntime(277): Shutting down VM
07-04 18:45:10.843: WARN/dalvikvm(277): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
07-04 18:45:11.191: ERROR/AndroidRuntime(277): FATAL EXCEPTION: main
07-04 18:45:11.191: ERROR/AndroidRuntime(277): android.content.res.Resources$NotFoundException: File res/layout/simple_spinner_item.xml …
Run Code Online (Sandbox Code Playgroud)

java android ddms

4
推荐指数
1
解决办法
2366
查看次数

龙卷风服务器上的SSL错误

我正在尝试创建一个HTTPS Web服务器.这是我的代码......

import tornado.escape
import tornado.ioloop
import tornado.web
import tornado.httpserver
import settings
import os
import ssl

class Application(tornado.web.Application):
    def __init__(self):
        handlers = [
            (r'/login', LoginPage),
        ]
        args = {
            'template_path': settings.TEMPLATE_PATH,
            'static_path': settings.STATIC_PATH,
            'debug': True,
            'cookie_secret': settings.COOKIE_SECRET,
            'login_url': settings.LOGIN_URL,
        }

        tornado.web.Application.__init__(self, handlers, **args)

class LoginPage(tornado.web.RequestHandler):
    def get(self):
        self.write("SSL. Yay!")


if __name__ == '__main__':
    applicaton = Application()
    ssl_options = {'certfile': os.path.join(settings.SSL_PATH, 'certificate.crt'),
                   'keyfile': os.path.join(settings.SSL_PATH, 'privateKey.key'),
    }
    http_server = tornado.httpserver.HTTPServer(applicaton, ssl_options=ssl_options)
    http_server.listen(8888)
    tornado.ioloop.IOLoop.instance().start()
Run Code Online (Sandbox Code Playgroud)

我使用以下命令生成了我的certificate.crt和privateKey.key ...

openssl req -x509 -nodes -days 365 -newkey …
Run Code Online (Sandbox Code Playgroud)

python ssl certificate tornado

4
推荐指数
1
解决办法
5947
查看次数

如何"随机"选择具有指定偏差的数字指向特定数字

如何生成具有指定偏差的随机数到一个数字.例如,我如何在两个数字1和2之间选择,偏向90%偏向1.我能想出的最好的是......

import random

print random.choice([1, 1, 1, 1, 1, 1, 1, 1, 1, 2])
Run Code Online (Sandbox Code Playgroud)

有一个更好的方法吗?我展示的方法在简单的例子中工作,但最终我将不得不做更复杂的选择,具有非常特殊的偏差(例如37.65%偏差),这需要很长的列表.

编辑:我应该补充说,我被困在numpy 1.6上,所以我不能使用numpy.random.choice.

python numpy scipy

3
推荐指数
1
解决办法
1997
查看次数

表不可编辑的mysql工作台错误

我有一个没有主键的表.我想做的就是查看数据.我不想编辑它.然而,每当我运行此查询时......

SELECT * FROM TableThatHasNoPrimaryKey  
Run Code Online (Sandbox Code Playgroud)

MySQL Workbench(版本5.2.36 v8542,在Ubuntu 10.04 64位上运行)给我这个错误...

table data is not editable because there is no primary key defined for the table
Run Code Online (Sandbox Code Playgroud)

这是一个错误吗?此查询在MySQL浏览器上显示数据.

mysql mysql-workbench

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

比较如果应该调用两次语句,但在比较一个整数时只调用一次

我有一个函数,它采用一个整数数组和一个布尔数组.如果Integer数组中的值为最高值且boolean数组为true,则trackerArray中的值设置为true.这是我的代码的简化版本,产生错误......

package com.thisis.a.test;

public class ThisIsATest {

    public static void main(String[] args){
        Integer[] integerArray = new Integer[]{75,200,75,200,75};
        boolean[] booleanArray = new boolean[]{false,true,false,true,false};
        boolean[] trackerArray   = new boolean[]{false,false,false,false,false};

        Integer iHighestSum = 0;
        for(int c = 0; c < booleanArray.length; c++){
            if(booleanArray[c] == true)
                if(integerArray[c] > iHighestSum)
                    iHighestSum = integerArray[c];
        }

        for(int c = 0; c < booleanArray.length; c++){
            if(booleanArray[c] == true)
                if(integerArray[c] == iHighestSum) 
                    trackerArray[c] = true; // this if statement should be called twice
        }

        // trackerArray should be {false,true,false,true,false} …
Run Code Online (Sandbox Code Playgroud)

java

0
推荐指数
1
解决办法
76
查看次数