我在python中使用稀疏矩阵输出,我需要将这个稀疏矩阵存储在我的硬盘中,我该怎么办?如果我应该创建一个数据库,那我该怎么办?这是我的代码:
import nltk
import cPickle
import numpy
from scipy.sparse import lil_matrix
from nltk.corpus import wordnet as wn
from nltk.corpus import brown
f = open('spmatrix.pkl','wb')
def markov(L):
count=0
c=len(text1)
for i in range(0,c-2):
h=L.index(text1[i])
k=L.index(text1[i+1])
mat[h,k]=mat[h,k]+1//matrix
cPickle.dump(mat,f,-1)
text = [w for g in brown.categories() for w in brown.words(categories=g)]
text1=text[1:500]
arr=set(text1)
arr=list(arr)
mat=lil_matrix((len(arr),len(arr)))
markov(arr)
f.close()
Run Code Online (Sandbox Code Playgroud)
我需要将这个"mat"存储在一个文件中,并且应该使用坐标来访问矩阵的值.
稀疏矩阵的结果是这样的:`稀疏矩阵的结果是这样的:
(173, 168) 2.0 (173, 169) 1.0 (173, 172) 1.0 (173, 237) 4.0 (174, 231) 1.0 (175, 141) 1.0 (176, 195) 1.0
Run Code Online (Sandbox Code Playgroud)
但是当我将它存储到一个文件中并阅读相同的内容时我会这样:
(0, 68) 1.0 …Run Code Online (Sandbox Code Playgroud) 我必须观察给出的任何输入或对文件中的当前内容所做的任何更改,在进行任何修改时我需要运行位于同一文件夹中的python程序.
我尽力了解,但我无法取得任何好成绩.如果有人能帮我解决这个问题,那将会有很大的帮助.
谢谢.. :)
如果我们提出查询:
select name from employee where id=23102 and sir_name="raj";
Run Code Online (Sandbox Code Playgroud)
我想知道使用哪种算法进行搜索?
当我在ubuntu中的Mysql客户端5.1中使用以下命令时:
load data infile 'words.csv' into table words;
Run Code Online (Sandbox Code Playgroud)
我收到这个错误:
ERROR 29 (HY000): File '/var/lib/mysql/bhuvan/words.csv' not found (Errcode: 2)
Run Code Online (Sandbox Code Playgroud)
帮帮我.
以前我在为python安装apache2时遇到错误,这是链接
我以为我应该继续那里,但是现在我得到一个新的错误,所以把它作为一个新的发布,这就是问题所在
我已经放置了一个包含代码的文件hello.py
#!/usr/bin/python
print "Content-type:text/html\r\n\r\n"
print '<html>'
print '<head>'
print '<title>Hello Word - First CGI Program</title>'
print '</head>'
print '<body>'
print '<h2>Hello Word! This is my first CGI program</h2>'
print '</body>'
print '</html>'
Run Code Online (Sandbox Code Playgroud)
/var/www/cgi-bin我在apache2上使用时在一个文件夹中
我收到了这个错误
The requested URL /cgi-bin/hello.py was not found on this server. Apache/2.2.14(Ubuntu)Server at localhost Port 80
Run Code Online (Sandbox Code Playgroud)
这是我在sites-available文件夹的默认页面中找到的代码:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from …Run Code Online (Sandbox Code Playgroud)