import tensorflow as tfprint('Tensorflow Version:{}'.format(tf.__version__))print(tf.config.list_physical_devices())
1.MNIST的数据集下载与预处理
import tensorflow as tf
from keras.datasets import mnist
from keras.utils import to_categorical(train_x,train_y),(test_x,test_y)= mnist.load_data()
X_train,X_test = tf.cast(train_x/255.0,tf.float32),tf.cast(test_x/255.0,tf.float32)# 归一化
y_train,y_test = to_categorical(train_y),to_categorical(test_y)# onehotprint(X_train[:5])print(y_train[:5])
2.搭建MLP模型
from keras import Sequential
from keras.layers import Flatten,Dense
from keras import Inputmodel = Sequential()
model.add(Input(shape=(28,28)))
model.add(Flatten())
model.add(Dense(units=256,kernel_initializer='normal',activation='relu'))
model.add(Dense(units=10,kernel_initializer='normal',activation='softmax'))
model.summary()
题目: 题解:
class Solution {
public:string addBinary(string a, string b) {string ans;reverse(a.begin(), a.end());reverse(b.begin(), b.end());int n max(a.size(), b.size()), carry 0;for (size_t i 0; i < n; i) {carry i < a.siz…
分类:字符串
知识点: 遍历字符串的每个字符 for char in my_str: 可以直接比较字符范围 a < char < z 列表统计元素个数 my_list.count(elem) 寻找子串 my_str.find(sub_str) 题目来自【牛客】 import re
import sysdef check_…
前言
今天在做一道宝石组合的题目时了解到了这个定理,还是蛮有意思的。
思想
唯一分解定理: 对于任何正整数n,有 n p 1 a 1 p 2 a 2 . . . p k a k n p_1^{a1} \times p_2^{a2} \times ... \times p_k^{ak} np1a1p2a2...pkak …