小编Geo*_*rge的帖子

如何在3D平面上投射点?

我有一个3D点(point_x,point_y,point_z),我想把它投影到3D空间的2D平面上,其中(平面)由点坐标(orig_x,orig_y,orig_z)和一元垂直向量(normal_dx)定义,normal_dy,normal_dz).

我该怎么处理?在此输入图像描述

c c++

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

如何将点投射到球体上

如果我有一个点(x,y,z)如何将它投影到球体(x0,y0,z0,半径)(在其表面上).我的输入将是点和球体的坐标.输出应该是球体上投影点的坐标.

只需从笛卡尔坐标转换为球坐标?

geometry coordinate-transformation

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

pycuda - 'CUDA_ROOT未设置,nvcc不在路径中.'

虽然我已经安装了pycuda并使用它,但它开始(没有做某事)不工作.所以,ii试图再次安装,但是当我做的时候

python configure.py --cuda-root =/usr/local/cuda/bin

它给了我标题中的错误.

nvcc文件位于上面的目录中.

pycuda

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

在 pytest 参数化中使用类型错误消息

我有一个函数,当满足某些条件时会引发 TypeError 。

def myfunc(..args here...):
    ... 
    raise TypeError('Message')
Run Code Online (Sandbox Code Playgroud)

我想使用 pytest parametrize 测试此消息。

但是,因为我正在使用其他参数,所以我也想要这样的设置:

testdata = [
        (..args here..., 'Message'), # Message is the expected output
    ]

    @pytest.mark.parametrize(
        "..args here..., expected_output", testdata)
    def test_myfunc(
       ..args here..., expected_output):

        obs = myfunc()
        assert obs == expected_output
Run Code Online (Sandbox Code Playgroud)

简单地将Message预期输出放入参数化测试数据中,就会导致测试失败。

python pytest

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

python无法通过电子邮件发送附件文件

我有以下代码工作正常,但它不发送附件文件.

import smtplib
import os
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.MIMEBase import MIMEBase
from email import Encoders

msg=MIMEMultipart()

def mymail(address,body,format,mylist=None):

    msg['To']=address
    msg['From']='ggous1@gmail.com'
    if format=='txt':
        text_msg=MIMEText(body,'plain')
    elif format=='html':
        text_msg=MIMEText(body,'html')
    msg.attach(text_msg)
    if mylist is not None:
        mylist=[]
        fn=[]
        for f in range(len(mylist)):
            direct=os.getcwd()
            os.chdir(direct)
            part=MIMEBase('application','octet-stream')
            part.set_payload(open(mylist[f],'rb').read())
            Encoders.encode_base64(part)
            part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(mylist[f])) 
            fn.append(part)
            msg.attach(fn)

    srv=smtplib.SMTP('smtp.gmail.com')
    srv.set_debuglevel(1)
    srv.ehlo()
    srv.starttls()
    srv.ehlo()
    srv.login('username','pass')
    srv.sendmail(msg['From'],msg['To'],msg.as_string())
    srv.quit()

if __name__=="__main__":
    address=raw_input('Enter an address to send email in the form "name@host.com" ')
    body=raw_input('Enter the contents …
Run Code Online (Sandbox Code Playgroud)

python email

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

在一天内保存用户数据(同一天 - >许多用户数据)

我有一个应用程序,用户在edittext中输入数据并按下保存按钮.

通过按"保存",我在文件中保存用户数据(在一列中)和当前日期(在另一列中).

然后,我按下另一个按钮并绘制图表(使用achartengine)日期(x轴)数据(y轴).

因此,在一天内输入数据会导致保存,例如:"1"(用户数据) - > 20/4/2013,"2" - > 20/4/2013,"3" - > 20/4/2013 .

在情节中,我在y轴上有3个点(ok),在x轴上有3个点(不是ok).

我想在x轴上有一个点,因为在同一天输入的数据.

我保存数据:

public void savefunc(){

        SimpleDateFormat thedate = new SimpleDateFormat("dd/MM/yyyy"); 
        Date d=new Date();

        String formattedDate=thedate.format(d);
        Log.d("tag","format"+formattedDate);
        dates_Strings.add(formattedDate);


        double thedata=Double.parseDouble(value.getText().toString().trim());
            mydata.add(thedata);


        File sdCard = Environment.getExternalStorageDirectory();
        File directory = new File (sdCard, "MyFiles");
        directory.mkdirs();            
        File file = new File(directory, filename);

        FileOutputStream fos;

        //saving them
        try {
           fos = new FileOutputStream(file);

              BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));
              for (int i=0;i<mydata.size();i++){
                 bw.write(mydata.get(i)+","+dates_Strings.get(i)+"\n");
              }
              ...
Run Code Online (Sandbox Code Playgroud)

如何在一天内保存用户数据?

也许有人检查一下: Date d=new Date(); …

java android achartengine

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

将变量从javascript传递给ejs

我想使用在javascript文件中声明的变量到ejs文件.

JavaScript的:

var express = require('express');
var app = express();

var myVar = 1;
Run Code Online (Sandbox Code Playgroud)

在ejs文件中,我想在几个if语句中使用该变量,我必须再次声明它才能使用它.

ejs文件:

var myVar = 1;
if ( my Var ) ....
Run Code Online (Sandbox Code Playgroud)

我怎么能避免这种情况?或者有没有办法创建一个可以从javascript和ejs访问的配置文件?

我也试过用:

app.locals.myVar = 1

但它在ejs文件中未定义.

-------更新--------------------------

在我的代码我正在使用:

app.get('/', function (req, res) {
    res.render('index', { user : req.user, message: [] });

});
Run Code Online (Sandbox Code Playgroud)

使用app.locals后:

app.get('/', function (req, res) {

   res.render('index', { user : req.user, message: [] });
   res.render('user_info.ejs');
Run Code Online (Sandbox Code Playgroud)

});

即使代码运行正常,我收到:

ReferenceError: ....user_info.ejs:18

 >> 18|            height:60px;


user is not defined
    at eval (eval at <anonymous> (...node_modules/ejs/lib/ejs.js:464:12), …
Run Code Online (Sandbox Code Playgroud)

javascript ejs node.js express

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

使用 pytest 参数夹具运行我得到的“self”未定义

我有这门课:

接受.py

class AcceptC(object):

    def __init__(self):
        self.minimum = 30
        self.maximum = 40
Run Code Online (Sandbox Code Playgroud)

和单元测试:

accept_test.py

import unittest
import pytest

from app.accept import AcceptC


class TestAcceptC(unittest.TestCase):

    def setUp(self):
        self.accept = AcceptC()


@pytest.mark.parametrize(
    "minimum, maximum, expected_min, expected_max", [
        ("13", "5", 30, 40),
        ("30", "40", 30, 40),
    ])
def test_init_returns_correct_results(minimum, maximum, expected_min, expected_max):
    expected_min = self.accept.minimum
    expected_max = self.accept.maximum
    self.assertEqual(minimum, expected_min)
    self.assertEqual(maximum, expected_max)


if __name__ == "__main__":
    unittest.main()
Run Code Online (Sandbox Code Playgroud)

使用 pytest 运行时,出现错误:

NameError: 名称 'self' 未定义

我还看到我不能self在测试函数中用作参数。

最后,有没有办法避免使用:

expected_min = self.accept.minimum
expected_max = …
Run Code Online (Sandbox Code Playgroud)

python pytest

6
推荐指数
2
解决办法
8817
查看次数

试图使路径工作 - 尝试相对导入超出顶级包

我不能做这个工作..

我的结构是:

program_name/

  __init__.py
  setup.py

  src/
    __init__.py

    Process/
        __init__.py
        thefile.py

  tests/
     __init__.py
     thetest.py
Run Code Online (Sandbox Code Playgroud)

thetest.py:

from ..src.Process.thefile.py import sth
Run Code Online (Sandbox Code Playgroud)

跑步:pytest ./tests/thetest.pyprogram_name给出:

ValueError: attempted relative import beyond top-level package

我也试过其他方法,但我收到各种错误.

但我希望以上工作能够奏效.

python pytest

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

tensorflow 2 api 回归 tensorflow.python.framework.ops.EagerTensor' 对象不可调用

我正在尝试使用 tensorflow 2 api 实现多元回归。

import tensorflow as tf
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

df = pd.DataFrame({'A': np.array([100, 105.4, 108.3, 111.1, 113, 114.7]),
                   'B': np.array([11, 11.8, 12.3, 12.8, 13.1,13.6]),
                   'C': np.array([55, 56.3, 57, 58, 59.5, 60.4]),
                   'Target': np.array([4000, 4200.34, 4700, 5300, 5800, 6400])})

X = df.iloc[:, :3].values
Y = df.iloc[:, 3].values

plt.scatter(X[:, 0], Y)
plt.show()

X = tf.convert_to_tensor(X, dtype=tf.float32)
Y = tf.convert_to_tensor(Y, dtype=tf.float32)

def poly_model(X, w, b):
    mult = tf.matmul(X, w)
    pred = …
Run Code Online (Sandbox Code Playgroud)

python-3.x tensorflow tensorflow2.0

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