包含标签 python 的文章

安装python3.9

安装python3.9 到网址找下载链接https://www.python.org/downloads/release/python-390/ 安装依赖 sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev 解压 tar -xf Python-3.X.X.tar.xz 设置并安装 which openssl //用命令查看openssl位置,设置的时候要用,不然安装好以后缺少openssl不能通过https下载包 ./configure --enable-optimizations --with-openssl=/usr/local/opt/openssl nproc //查看进程数 make -j 4 //此处的数字是进程数 sudo make altinstall (sudo make install) //make install 会直接覆盖系统的python 安装lxml遇到问题 cc -I/usr/include/libxml2 -I/usr/include/libxml2 -c /tmp/xmlXPathInitcfhhalla.c -o tmp/xmlXPathInitcfhhalla.o cc tmp/xmlXPathInitcfhhalla.o -lxml2 -o a.out error: command '/usr/bin/gcc' failed with exit code 4 有可能是内存不够,我的机器512MB不够,增加虚拟内存到2G以后安装成功……

阅读全文

jupyter使用xgboost服务挂掉

发生错误 OMP: Error #15: Initializing libiomp5.dylib, but found libiomp5.dylib already initialized. 1 import os os.environ['KMP_DUPLICATE_LIB_OK']='True' 2 安装nomkl conda install nomkl 参考https://github.com/dmlc/xgboost/issues/1715……

阅读全文

使用ibmcloud

创建资源 安装使用 IBM Cloud CLI https://console.bluemix.net/docs/cli/index.html#overview ibmcloud api https://api.ng.bluemix.net ibmcloud login -u [email protected] -o [email protected] -s dev //上传 bluemix app push pythondjangotest 创建项目 django-admin startproject mysite cd mysite //上传程序要在这个目录执行上传命令 python3 manage.py startapp helloworld 解决依赖 pip3 freeze > requirements.txt chardet==2.3.0 Django==2.1.7 gunicorn==19.9.0 httplib2==0.9.2 pycurl==7.43.0 pytz==2018.9 reportbug==7.1.7 requests==2.12.4 six==1.10.0 urllib3==1.19.1 uWSGI==2.0.18 在目录下新建runtime.txt,并添加python版本 例如: python-3.6.4 遇到错误 bluemix cf set-env pythondjangotest DISABLE_COLLECTSTATIC 1 bluemix cf restage pythondjangotest Procfile文件 web: gunicorn mysite.wsgi bluemix app push pythondjangotest 各种问题 python3……

阅读全文

线性回归

Linear Regression_Intro page 10 生成数据 NumberObservations=100 minVal=1 maxVal=20 X = np.random.uniform(minVal,maxVal,(NumberObservations,1)) print(X.shape) #Add you code below to define error and Y based on the information above def generateY(x): Y = np.array(100) Y = 10 + 5*x #print(Y) gaussian_noise = np.random.normal(0, 1, 100).reshape(100,1) #print(gaussian_noise) Y = Y + gaussian_noise return Y Y = generateY(X) print(Y) 线性回归 def calculate_RSS(B0, B1, testX, testY): testX = np.array(testX) testY = np.array(testY) predictY = testX*B1+B0 RSS = sum((testY-predictY)*(testY-predictY)) return RSS def linear_regression(B0, B1, trainX, trainY, iteration=10000, learning_rate=0.……

阅读全文

python相关

numpy #正态分布 import numpy as np np.random.normal(0, 1, 100) #μ=0,σ=1 DataFrame增加一列 df['new_column'] = data df.insert(index, 'flag', array) DataFrame选择两列 df[['a','b']] pd.DataFrame(df,columns = ['s','b']) python plot plt.plot(df['a'], df['b'], 'o') plt.show() 保存文件时索引 https://blog.csdn.net/sinat_29957455/article/details/79059436 fluent python 相关 列表推导和生成器表达式 symbols = '$%x' codes = [ord(symbol) for symbol in symbols] #以下效果相同 beyond_ascii = [ord(s) for s in symbols if ord(s)>127] beyond_ascii = list(filter(lambda c: c>127, map(ord,symbols))) 文件读写 try: f = open('file', 'r') print(f.read()) finally: if f: f.……

阅读全文