This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class QuickFindUF | |
{ | |
private int [ ] id; | |
public QuickFindUF( int N) | |
{ | |
id = new int[N]; # set id of each object to itself { N array accesses} | |
for ( int i = 0 ; i < N ; i ++) | |
id[ i ] = i ; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import absolute_import, division, print_function, unicode_literals | |
import tensorflow as tf | |
mnist = tf.keras.datasets.mnist | |
(x_train, y_train), (x_test, y_test) = mnist.load_data() | |
x_train, x_test = x_train / 255.0, x_test / 255.0 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
a = tf.constant(1, name='a') | |
b = tf.constant(1, name='b') | |
c = a+b | |
with tf.Session as sess: #注意以上的session將a,b 視為個體, 否則跑出來的結果會為不同 | |
print(sess.run(c)) | |
import tensorflow as tf | |
a = tf.constant(1, name='a') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bs4 import BeautifulSoup as soup | |
fin=open('web.htm', encoding='utf-8') #將html檔案放置 web.htm(再轉換到fin開啟) | |
s=fin.read() | |
htm=soup(s,'html.parser') | |
print(htm.title.prettify()) | |
print(htm.title.contents) | |
print(htm.contents[0]) | |
print(htm.title.name) | |
print(htm.title.string) | |
print(htm.meta) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from FinMind.Data import Load | |
import numpy as np | |
#import pandas as pd | |
from keras.layers.core import Dense, Dropout | |
from keras.layers import LSTM , GRU | |
from keras.models import Sequential | |
from sklearn.preprocessing import MinMaxScaler | |
import matplotlib.pyplot as plt | |
import math | |
from keras.optimizers import Adam |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#這邊會介紹把網頁後端的程式碼抓下來的結果以及會使用到的指令 | |
import urllib.request as ur #先把模組簡單匯入 | |
url="https://看你需要甚麼網站的名稱" #輸入自己要的網站 | |
resp=ur.urlopen(url) #暫時存在ur裏頭 | |
data=resp.read() #data會在暫存器里先讀取 | |
print(data) | |
#以下毒出來的資料皆為byte,你也可以用decode函數轉換成字串 | |
#但是urllib.request的程式碼較為複雜 比較建議使用request的第三方模組,得出的結果也會較為簡潔 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#首先你必須用 pip install matplotlib | |
#等他下載完成,你就可以使用模組去進行數據視覺化的動作 | |
import matplotlib.pyplot as plt | |
data=[5,10,15,25,20] #把你需要的data數值用出來 | |
plt.barh(range(len(data)),data) #圖片會顯示你data長度和範圍 | |
plt.show() | |
#是不是很簡單呀 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#再windos按鈕畫面點擊右鍵(並按下執行) | |
#先在cmd 命令提示字元 輸入python再輸入import this | |
#將那段話存入 xxx.txt | |
from collections import Counter #記住從from 甚麼 import 甚麼都要放在第一行 以免篩選器錯誤 | |
fin=open('xxx.txt','rt') | |
s=fin.read().lower() #物件fin 使用函式read一次讀取所有內容, 使用函式lower將所有字母轉換小寫 | |
words=re.findall(r'[\w\']+',s) #用re.findall找出大小寫字母、數字、底線、和單引號 | |
c=Counter(words) #將物件counter以words為輸入, 將獲得的counter物件轉換成c | |
print(c.most_common(5)) #把c內容最常出現的五個屬性字找出 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re #匯入模組 #這個符號是python拿來解釋用的歐 | |
s='君不見黃河之水天上來,奔流到海不復回。\ | |
君不見高堂明鏡悲白髮,朝如青絲暮成雪。 | |
人生得意須盡歡,莫使金樽空對月。\ | |
天生我材必有用,千金散盡還復來。\ | |
烹羊宰牛且爲樂,會須一飲三百杯。\ | |
岑夫子,丹丘生。將進酒,杯莫停。\ | |
與君歌一曲,請君爲我側耳聽。\ | |
鐘鼓饌玉不足貴,但願長醉不願醒。\ | |
古來聖賢皆寂寞,惟有飲者留其名。\ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print('我是小帥哥'.encode('unicode-escape')) #將【我是一個小帥哥】以函式encode以 (unicode-escape)進行編碼 | |
def utf8(data): #定義utf-8 | |
data_byte=data.encode('utf-8') #回傳data的utf-8編碼結果指定給data_byte | |
data2=data_byte.decode('utf-8') | |
print('將',data,'經由utf-8編碼後為',data_byte) | |
print('將',data_byte,'經由utf-8解碼後為',data2) | |
print(data,'的長度為',len(data)) #將data長度顯示於螢幕上 | |
print(data_byte,'的長度為',len(data_byte)) #將data_byte長度顯示於螢幕上 | |
utf('我是一個小帥哥') | |
utf("b'\\u6211\\u662f\\u5c0f\\u5e25\\u54e5'") |
NewerOlder