Tensorflow小技巧(一)
how-do-i-select-rows-from-a-dataframe-based-on-column-values
To select rows whose column value equals a scalar, some_value, use ==:
df.loc[df['column_name'] == some_value]
To select rows whose column value is in an iterable, some_values, use isin:
df.loc[df['column_name'].isin(some_values)]
how-do-i-sort-a-dictionary-by-value
x = {1: 2, 3: 4, 4: 3, 2: 1, 0: 0}
dict(sorted(x.items(), key=lambda item: item[1]))
how-can-i-count-the-occurrences-of-a-list-item
from collections import Counter l = ["a","b","b"] Counter(l)
pandas.DataFrame.drop_duplicates
df = pd.DataFrame({
... 'brand': ['Yum Yum', 'Yum Yum', 'Indomie', 'Indomie', 'Indomie'],
... 'style': ['cup', 'cup', 'cup', 'pack', 'pack'],
... 'rating': [4, 4, 3.5, 15, 5]
... })
df.drop_duplicates(subset=['brand'])
tf.data.Dataset-----as_numpy_iterator()
Returns an iterator which converts all elements of the dataset to numpy.
dataset = tf.data.Dataset.from_tensor_slices([1, 2, 3]) for element in dataset.as_numpy_iterator(): print(element)
tf.data.Dataset
The tf.data.Dataset API supports writing descriptive and efficient input pipelines. Dataset usage follows a common pattern:
-
Create a source dataset from your input data.
-
Apply dataset transformations to preprocess the data.
-
Iterate over the dataset and process the elements.
Iteration happens in a streaming fashion, so the full dataset does not need to fit into memory.
The simplest way to create a dataset is to create it from a python list:
dataset = tf.data.Dataset.from_tensor_slices([1, 2, 3]) for element in dataset: print(element)
Once you have a dataset, you can apply transformations to prepare the data for your model:
dataset = tf.data.Dataset.from_tensor_slices([1, 2, 3]) dataset = dataset.map(lambda x: x*2) list(dataset.as_numpy_iterator())
相关推荐
轻松实现TensorFlow微信跳一跳的AI
在标签中,“微信跳一跳”、“TensorFlow微信跳一跳AI”、“TensorFlow微信跳一跳”和“python微信跳一跳”均与本文的主题相关,表明我们将探讨如何使用Python编程语言和TensorFlow
Tensorflow(一)训练自己的数据集——猫狗图片
尽管这是一个小型项目,但它涵盖了深度学习和Tensorflow的基础概念,对于初学者来说是一个理想的起点。通过实践这个项目,你将能够更好地理解和应用Tensorflow进行实际的图像分类任务。
Tensorflow DCGAN的踏坑之路(一)
**TensorFlow 1.x与2.x的区别**在上述文章中提到,原代码依赖于TensorFlow 0.12.1,而当前版本已经到了2.x。
TensorFlow2.0学习笔记(一)
综上所述,这篇学习笔记涵盖了TensorFlow 2.0的核心概念,从数据处理到模型构建,再到模型优化和超参数搜索,为理解和实践TensorFlow提供了一个全面的起点。
tensorflow学习(一)
"本资源是关于TensorFlow学习的初步教程,主要介绍了如何构建一个三层全连接的分类神经网络。利用tf.keras.model.Sequential API来搭建模型,数据预处理使用了numpy


