我想在 tensorflow 上运行 keras fit 后腌制历史对象。但我收到一个错误。
import gzip
import numpy as np
import os
import pickle
import tensorflow as tf
from tensorflow import keras
with gzip.open('mnist.pkl.gz', 'rb') as f:
train_set, test_set = pickle.load(f, encoding='latin1')
X_train = np.asarray(train_set[0])
y_train = np.asarray(train_set[1])
X_test = np.asarray(test_set[0])
y_test = np.asarray(test_set[1])
X_valid, X_train = X_train[:5000]/255.0, X_train[5000:]/255.0
y_valid, y_train = y_train[:5000], y_train[5000:]
class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',
'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle Boot']
model = keras.models.Sequential()
model.add(keras.layers.Flatten(input_shape=[28,28]))
model.add(keras.layers.Dense(300, activation = 'relu'))
model.add(keras.layers.Dense(100, activation = …Run Code Online (Sandbox Code Playgroud) 所以我一直在互联网上查找,但我无法找到如何在没有 for 循环 + if 语句的情况下做到这一点。假设我有这个作为我的数组:
import numpy as np
a = np.array([361, 362, 363, 364, 365, 0, 1, 2, 366, 367])
Run Code Online (Sandbox Code Playgroud)
我想找出第一个最高值(无论将来是否有另一个更高的值),在本例中为365. 这就是我在不使用 numpy 的情况下执行此操作的方法:
import numpy as np
a = np.array([361, 362, 363, 364, 365, 0, 1, 2, 366, 367])
for element in range(a.shape[0]-1):
if a[element+1] < a[element]:
first_max = a[element]
break
print(first_max)
# 365
Run Code Online (Sandbox Code Playgroud)
有没有办法使用 numpy 函数来做到这一点?
我在 C 函数中找不到格式说明符部分printf。我已经man printf在我的 Linux 发行版上做了一个,但它没有提供该信息。
到目前为止,每次我需要找到一种格式时,我都会进行谷歌搜索。我确信这个问题之前已经在 stackoverflow 上被问过,但我找不到它。