Tensorflow小技巧(一)

简介: 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:

  1. Create a source dataset from your input data.
  2. Apply dataset transformations to preprocess the data.
  3. 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())
目录
相关文章
|
5月前
|
机器学习/深度学习 TensorFlow API
精通 TensorFlow 1.x:1~5(2)
精通 TensorFlow 1.x:1~5(2)
107 0
|
机器学习/深度学习 TensorFlow API
tensorflow详解
@[TOC](目录) TensorFlow 是一个由 Google Brain 团队开发的高级开源机器学习框架,旨在为开发者提供一种灵活、高效的方式来构建和训练神经网络模型,以及进行各种机器学习任务,如文本分析、图像识别、自然语言处理等。TensorFlow 提供了丰富的 API 和工具,使开发者可以轻松地构建、训练和部署深度学习模型 # 1. 基本介绍 TensorFlow 是一个开源的深度学习框架,由 Google Brain 团队开发和维护。它可以用于构建各种类型的神经网络,包括卷积神经网络、循环神经网络、生成对抗网络等。TensorFlow 提供了丰富的 API 和工具,使得开发者可以
238 0
|
机器学习/深度学习 自然语言处理 搜索推荐
TensorFlow详解
TensorFlow是一个开源的机器学习框架,由Google开发。它是一个强大、高度可扩展的计算框架,可以用于各种机器学习任务,包括图像和语音识别、自然语言处理、推荐系统等。 TensorFlow 是一种由 Google 开发的开源机器学习框架,它可以帮助我们构建和训练机器学习模型。无论您是一名初学者还是一名专业人士,本文将为您提供一份完整的 TensorFlow 指南,帮助您了解 TensorFlow 的基础知识,以及如何在实际项目中应用它。
158 0
|
7天前
|
机器学习/深度学习 人工智能 TensorFlow
TensorFlow
【10月更文挑战第04天】
19 8
|
3月前
|
机器学习/深度学习 人工智能 TensorFlow
TensorFlow介绍
【7月更文挑战第21天】TensorFlow介绍。
41 2
|
4月前
|
机器学习/深度学习 算法 TensorFlow
TensorFlow
【6月更文挑战第26天】TensorFlow。
42 7
|
5月前
|
机器学习/深度学习 TensorFlow 算法框架/工具
精通 TensorFlow 1.x:11~15(2)
精通 TensorFlow 1.x:11~15(2)
73 0
|
5月前
|
机器学习/深度学习 TensorFlow API
TensorFlow 2.0简单介绍及使用
TensorFlow 2.0简单介绍及使用
|
5月前
|
Kubernetes TensorFlow 算法框架/工具
精通 TensorFlow 1.x:11~15(1)
精通 TensorFlow 1.x:11~15(1)
61 0
|
5月前
|
机器学习/深度学习 TensorFlow 算法框架/工具
精通 TensorFlow 1.x:11~15(5)
精通 TensorFlow 1.x:11~15(5)
53 0