TensorflowSimilarity学习笔记2

2021SC@SDUSC

 代码位置:https://github.com/tensorflow/similarity/blob/master/tensorflow_similarity/types.py 

# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Core TensorFlow types."""

import dataclasses
from typing import Any, Callable, Mapping, Sequence, Optional, Union

import numpy as np
import tensorflow as tf
from tensorflow import Tensor


class PandasDataFrame(object):
    """Symbolic pandas frame
    Pandas type are too loose you get an Any. We want a DataFrame
    """
    pass


class BoolTensor(Tensor):
    """Bool tensor """


class FloatTensor(Tensor):
    """Float tensor """


class IntTensor(Tensor):
    """Integer tensor"""


class Symbol(Tensor):
    """Symbolic "graph" Tensor.

    These objects represent the output of an op definition and do not carry a
    value.
    """
    pass


class Value(Tensor):

TensorFlow 程序使用张力数据结构来表示所有数据。我们可以将 TensorFlow 张伸器视为 n 维阵列或列表。张力器具有静态类型和动态尺寸。计算图中的节点之间只能传递张力。

Rank

在 TensorFlow 系统中,张力被称为等级的维度单位描述。紧张级与矩阵排名不同。张力等级(有时称为顺序、度或 n 维)是张力的维度数。例如,以下张力(定义为 Python 列表)的排名为 2:

t = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

排名二张张力是我们通常认为的矩阵,一级张力器是载体。对于二级紧张器,您可以用语法 t [i, j] 来合成任何元素。对于三级紧张器,您需要用 t[i,j,k]来处理一个元素。

Shape

TensorFlow 文档使用三个符号约定来描述张力维度:排名、形状和维度编号。下表显示了这些相互关联性:

形状可以通过 Python 列表 / 国际数字图或 TensorShape 类来表示。

Data Types

除了维度外,Tensors 还具有数据类型。您可以将以下任何一种数据类型分配给张力器:

PandasDataFrame:

DataFrame 是一种 2 维标记数据结构,具有可能不同类型的列。您可以将其想象成电子表格或 SQL 表,或系列对象的听写。它通常是最常用的熊猫对象。与系列一样,DataFrame 接受多种不同的输入:

1D ndarray、列表、dict 或系列的 Dict

2 - d 南皮. n 达雷

结构化或录制 ndarray

系列

另一个数据框架

除了数据,您还可以可选地通过索引(行标签)和列(列标签)参数。如果您通过索引和 / 或列,则您正在保证生成的数据框架的索引和 /或列。因此,系列加特定索引的听写将丢弃与通过的索引不匹配的所有数据。

如果轴标签未通过,则它们将基于常识规则从输入数据构建。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值