小编tor*_*rho的帖子

从命令行(终端)启动Pycharm

我想尝试PyCharm进行鼠尾草数学开发.通常我运行eclipse来进行sage开发,但现在我想用PyCharm尝试它.

要使用sage环境变量启动eclipse,在命令行中我通常会执行以下操作:

sage -sh
cd /path/to/eclipse
./eclipse
Run Code Online (Sandbox Code Playgroud)

第一行加载sage环境变量,其余部分启动eclipse.我怎么能为pyCharm做同样的事情?(注意我使用Mac和Ubuntu进行sage开发;上面的命令对两个操作系统都是不可知的)

  1. 链接1接近我正在寻找的解决方案,但我无法在任何地方找到pyCharm.sh.
  2. 链接2:Jetbrains也没有给出明确的指示.

python command-line environment-variables sage pycharm

42
推荐指数
7
解决办法
8万
查看次数

如何创建一个总和为x的随机整数向量列表

创建一个总和为X的随机向量(例如X = 1000)非常简单:

import random
def RunFloat():
    Scalar = 1000
    VectorSize = 30
    RandomVector = [random.random() for i in range(VectorSize)]
    RandomVectorSum = sum(RandomVector)
    RandomVector = [Scalar*i/RandomVectorSum for i in RandomVector]
    return RandomVector
RunFloat()
Run Code Online (Sandbox Code Playgroud)

上面的代码创建了一个向量,其值为浮点数,sum为1000.

我很难创建一个简单的函数来创建一个值为整数且和为X的向量(例如X = 1000*30)

import random
def RunInt():
    LowerBound = 600
    UpperBound = 1200
    VectorSize = 30
    RandomVector = [random.randint(LowerBound,UpperBound) for i in range(VectorSize)]
    RandomVectorSum = 1000*30
    #Sanity check that our RandomVectorSum is sensible/feasible
    if LowerBound*VectorSize <= RandomVectorSum and RandomVectorSum <= UpperBound*VectorSum:
        if sum(RandomVector) == RandomVectorSum:
            return …
Run Code Online (Sandbox Code Playgroud)

python random list

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

在python中将字符串视为文件

为了重写开源库,我想将一串文本视为python 3中的文件.

假设我将文件内容作为字符串:

not_a_file = 'there is a lot of blah blah in this so-called file'
Run Code Online (Sandbox Code Playgroud)

我想把这个变量,即文件的内容,作为一个 类似路径的对象,我可以在python的open() 函数中使用它.

这是一个显示我的困境的简单例子:

not_a_file = 'there is a lot of blah blah in this so-called file'
file_ptr = open(not_a_file, 'r')
Run Code Online (Sandbox Code Playgroud)

显然,该示例不起作用,因为not_a_file它不是类似路径的对象.我不想编写文件,也不想为了可移植性目的创建任何临时目录.

话虽如此,我需要解决这个谜团:

not_a_file = 'there is a lot of blah blah in this so-called file'
... Something goes here ... 
file_ptr = open(also_not_a_file, 'r') 
Run Code Online (Sandbox Code Playgroud)

我到目前为止所做的一切

  1. 我已经研究过StringIO并尝试将其用作路径式对象并且没有骰子: import StringIO output = StringIO.StringIO() output.write('First line.\n') file_ptr = open(output,'r') …

python string io

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

伽罗瓦域的快速求幂

我希望能够计算

g^x = g * g * g * ... * g     (x times)
Run Code Online (Sandbox Code Playgroud)

其中 g 位于有限域 GF(2^m) 中。这里 m 相当大,m = 256、384、512 等,因此查找表不是解决方案。我知道有类似想法的快速算法,modpow for Z/nZ(参见HAC第 619-620 页)。

  1. 什么是快速、非基于表格的计算周期的方法(即 g^x)?
  2. 这绝对是一个一厢情愿的问题,但问题来了:蒙哥马利乘法/求幂的想法可以“回收”到伽罗瓦域吗?我想这样认为,因为同构特性,但我真的不知道。

备注:这是我在 math.stackoverflow.com 上的帖子,我认为这是提出这个问题的最佳社区。

multiplication polynomial-math exponentiation galois-field finite-field

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

编译错误致命错误:sys \ types.h:没有这样的文件或目录#include &lt;sys \ types.h&gt;

我一直在寻找解决方案。当然,这些链接可以暗示一件事或另一件事:

错误:sys / types.h找不到这样的目录

致命错误:sys / socket.h:32位上没有此类文件或目录

错误:sys / types.h找不到这样的目录

和其他类似的链接。

让我给你错误,相关的Makefile语句,并告诉我我的包含目录结构。

错误

gcc -o obj/nmlflpth.o -std=c99 -Ilarc/include -Ilarc/modules/include -Ilarc/milesup -Ilarc/pftk -Ilarc/npsol -Ilarc/src -Ilarc/uih -Ilarc/util -Ilarc/uopt -Ilarc/pgm -Ilarc/navlrc -Ilarc/modules/production/common -Ilarc/src_test -Ilarc/gtest/include -c -O2 larc/uih/nmlflpth.c
larc/uih/nmlflpth.c:48:23: fatal error: sys\types.h: No such file or directory
#include <sys\types.h>
Run Code Online (Sandbox Code Playgroud)

相关的Makefile语句

# list of all dirs with compilable C, C++ and F77 code
dirs    :=  larc/milesup \
            larc/pftk \
            larc/npsol \
            larc/src \
            larc/uih \
            larc/util \
            larc/uopt \
            larc/pgm \
            larc/navlrc \
            larc/modules/production/common

# …
Run Code Online (Sandbox Code Playgroud)

c compiler-errors makefile compilation

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