linux自学小结

1 安装软件方法:

sudo apt-get install xxxx
如果出现错误:有未能满足的依赖关系,就输入
sudo apt-get -f install
再重新输入sudo apt-get install xxx即可
dpkg -s xxxx检查安装是否成功
以后也可以尝试用aptitude替代apt-get
sudo apt-get install aptitude
再使用sudo aptitude install xxxx

2 vim的使用

vim /home/zhangjin/zhangjinming/zhangjinming_0906.py

并按i进入编辑模式,输入:

#-*- coding:utf-8 -*-
import tensorflow as tf
import numpy as np
x_data=np.random.rand(100).astype(np.float32)
y_data=x_data*0.1+0.3
#tf.random_uniform()的参数的意义(shape,min,max)
weights=tf.Variable(tf.random_uniform([1],-1.0,1.0))
biases=tf.Variable(tf.zeros([1]))
y=weights*x_data+biases
#损失函数,tf.reduce_mean()是取均值
loss=tf.reduce_mean(tf.square(y-y_data))
#用梯度优化方法最小化损失函数
optimizer=tf.train.GradientDescentOptimizer(0.5)
train=optimizer.minimize(loss)
#tf变量初始化
init=tf.global_variables_initializer()
#进行计算
with tf.Session() as sess:
    sess.run(init)
    for step in range(201):
        sess.run(train)
        if step%20==0:
            print step,sess.run(weights), sess.run(biases)

注意python2中print语句是 print xxx

按esc退出编辑模式

:wq表示保存后离开
:q!表示不保存并强制离开
:w表示保存文件

然后选择python zhangjinming_0906.py即可

3 bash脚本

新建脚本文本 test1.sh

#! /bin/bash
echo "what's your name?"
read PERSON
echo "Hello, $PERSON"

然后依次在命令行输入

cd /home/zhangjin/zhangjinming
chmod +x ./test.sh  #使脚本具有执行权限
./test.sh  #执行脚本

4 VMware连不上网

启动WMmare DHCP service与WMware NAT service

5 PyCharm下的自由游走程序

##bug
import matplotlib时显示未安装matplotlib包,打开pycharm的setting-Project Interpreter中安装时显示fail to install python packaging tool No module named setuptool

##解决方法
###1 安装jdk

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

###2 安装python3-pip
sudo apt install python3-pip
###3 pycharm-setting-project interpreter-安装matplotlib
###4 ImportError: No module named ‘_tkinter’

sudo apt search python3-tk
sudo apt install python3-tk

附上代码

from random import choice
class RandomWalk():
    def __init__(self,num_points=5000):
        self.num_points=num_points
        self.x_values=[0]
        self.y_values=[0]

    def fill_walk(self):
        while len(self.x_values) <self.num_points:
            x_direction=choice([1,-1])
            x_distance=choice([0,1,2,3,4])
            x_step=x_direction*x_distance
            y_direction=choice([1,-1])
            y_distance=choice([0,1,2,3,4])
            y_step=y_direction*y_distance

            if x_step==0 and y_step==0:
                continue

            next_x=self.x_values[-1]+x_step
            next_y=self.y_values[-1]+y_step
            self.x_values.append(next_x)
            self.y_values.append(next_y)
import matplotlib.pyplot as plt
from random_walk import RandomWalk
rw=RandomWalk()
rw.fill_walk()

point_number=list(range(rw.num_points))
plt.scatter(rw.x_values,rw.y_values,c=point_number,cmap=plt.cm.Blues,edgecolors='none',s=15)
plt.scatter(0,0,c='green',edgecolors='none',s=100)
plt.scatter(rw.x_values[-1],rw.y_values[-1],c='red',edgecolors='none',s=100)
#plt.scatter(rw.x_values,rw.y_values,s=15)
plt.show()

6 linux常用指令

mkdir tmp 创建文件夹
cp test.sh ./python/test2.sh 复制
rm -r tmp 删除文件夹
rm ./python/test2.sh 删除文件
cat test.sh 查看文件内容
find [目录] -name "正则表达式" 查找文件名
find . -name "*.py"
pwd 显示当前工作目录
ls 查看工作目录文件
shutdown 关机
cd ..表示返回上一级目录
sudo fdish -l查看硬盘分区
df -h查看硬盘空间大小
~/表示/home/zhangjin/这个目录
./表示当前目录
../表示上级目录

7 python可视化

import requests
json_url='https://raw.githubusercontent.com/muxuezi/btc/master/btc_close_2017.json'
req=requests.get(json_url)
file_requests=req.json()
dates=[]
months=[]
weeks=[]
weekdays=[]
closes=[]
for btc_dict in file_requests:
    dates.append(btc_dict['date'])
    months.append(int(btc_dict['month']))
    weeks.append(int(btc_dict['week']))
    weekdays.append(btc_dict['weekday'])
    closes.append(int(float(btc_dict['close'])))
print(dates)
import math
import pygal
line_chart.x_labels=dates
N=20
line_chart.x_labels_major=dates[::N]
line_chart.add('收盘价',closes)
line_chart.render_to_file('收盘价对数折线.svg')

开始时svg显示不出来,后来才知道svg格式的图片需要用浏览器打开
pygal是一个svg图表库,svg是一种矢量图格式,可任意缩放

#8 makefile命令
vim makefile

edit:helo.o
    gcc hello.o -o edit
    
hello.o:hello.c
    gcc hello.o -c hello.c

make
##bug
makefile:missing separator
##解决
vimrc中去掉set expandtab即可
#makefile语法
目标文件:需要用到的文件
[tab]指令

猜你喜欢

转载自blog.csdn.net/tiaozhanzhe1900/article/details/82748027