当前位置: 首页 > news >正文

怎么在服务器做网站企业电子邮箱怎么注册

怎么在服务器做网站,企业电子邮箱怎么注册,如何建设一个公众号电影网站,wordpress商品左移窗口在这篇文章中#xff0c;我们将深入研究Tensorflow Tensor的细节。我们将在以下五个简单步骤中介绍与Tensorflow的Tensor中相关的所有主题#xff1a;第一步#xff1a;张量的定义→什么是张量#xff1f;第二步#xff1a;创建张量→创建张量对象的函数第三步#xff1a…在这篇文章中我们将深入研究Tensorflow Tensor的细节。我们将在以下五个简单步骤中介绍与Tensorflow的Tensor中相关的所有主题第一步张量的定义→什么是张量第二步创建张量→创建张量对象的函数第三步张量对象的特征第四步张量操作→索引、基本张量操作、形状操作、广播第五步特殊张量张量的定义什么是张量张量是TensorFlow的均匀型多维数组。它们非常类似于NumPy数组并且它们是不可变的这意味着一旦创建它们就不能被更改。只能使用编辑创建新副本。让我们看看张量如何与代码示例一起工作。但是首先要使用TensorFlow对象我们需要导入TensorFlow库。我们经常将NumPy与TensorFlow一起使用因此我们还可以使用以下行导入NumPyimport tensorflow as tfimport numpy as np张量的创建创建张量对象有几种方法可以创建tf.Tensor对象。让我们从几个例子开始。可以使用多个TensorFlow函数创建张量对象如下例所示# 你可以用tf.constant函数创建tf.Tensor对象:x tf.constant([[1, 2, 3, 4 ,5]])# 你可以用tf.ones函数创建tf.Tensor对象:y tf.ones((1,5))# 你可以用tf.zeros函数创建tf.Tensor对象:z tf.zeros((1,5))# 你可以用tf.range函数创建tf.Tensor对象:q tf.range(start1, limit6, delta1)print(x)print(y)print(z)print(q)输出tf.Tensor([[1 2 3 4 5]], shape(1, 5), dtypeint32)tf.Tensor([[1. 1. 1. 1. 1.]], shape(1, 5), dtypefloat32) tf.Tensor([[0. 0. 0. 0. 0.]], shape(1, 5), dtypefloat32) tf.Tensor([1 2 3 4 5], shape(5,), dtypeint32)如你所见我们使用三个不同的函数创建了形状(1,5)的张量对象使用tf.range()函数创建了形状(5,)的第四个张量对象。注意,tf.ones的和tf.zeros接受形状作为必需的参数因为它们的元素值是预先确定的。张量对象的特征tf.Tensor创建对象它们有几个特征。首先他们有维度数量。其次它们有一个形状一个由维度的长度组成的列表。所有张量都有一个大小即张量中元素的总数。最后它们的元素都被记录在一个统一的数据类型(datatype)中。让我们仔细看看这些特征。维度张量根据其维数进行分类Rank-0(标量)张量包含单个值且没有轴的张量(0维)Rank-1张量包含单轴(一维)值列表的张量Rank-2张量包含2个轴(2维)的张量以及Rank-N张量包含N轴的张量(三维)。例如我们可以通过向tf.constant传递一个三层嵌套的list对象来创建一个Rank-3张量。对于这个例子我们可以将数字分割成一个3层嵌套的列表每个层有3个元素:three_level_nested_list [[[0, 1, 2], [3, 4, 5]], [[6, 7, 8], [9, 10, 11]] ]rank_3_tensor tf.constant(three_level_nested_list)print(rank_3_tensor)Output:tf.Tensor( [[[ 0 1 2] [ 3 4 5]] [[ 6 7 8] [ 9 10 11]]], shape(2, 2, 3), dtypeint32)我们可以查看“rank_3_tensor”对象当前具有“.ndim”属性的维度数。tensor_ndim rank_3_tensor.ndimprint(The number of dimensions in our Tensor object is, tensor_ndim)Output:The number of dimensions in our Tensor object is 3形状形状特征是每个张量都具有的另一个属性。它以列表的形式显示每个维度的大小。我们可以查看使用.shape属性创建的rank_3_tensor对象的形状如下所示tensor_shape rank_3_tensor.shapeprint(The shape of our Tensor object is, tensor_shape)Output:The shape of our Tensor object is (2, 2, 3)如你所见我们的张量在第一层有两个元素第二层有两个元素第三层有三个元素。大小大小是张量的另一个特征它意味着张量有多少个元素。我们不能用张量对象的属性来测量大小。相反我们需要使用tf.size函数。最后我们将使用实例函数.NumPy()将输出转换为NumPy以获得更具可读性的结果tensor_size tf.size(rank_3_tensor).numpy()print(The size of our Tensor object is, tensor_size)Output:The size of our Tensor object is 12数据类型张量通常包含数字数据类型如浮点和整数但也可能包含许多其他数据类型如复数和字符串。但是每个张量对象必须将其所有元素存储在一个统一的数据类型中。因此我们还可以使用.dtype属性查看为特定张量对象选择的数据类型如下所示tensor_dtype rank_3_tensor.dtypeprint(The data type selected for this Tensor object is, tensor_dtype)Output:The data type selected for this Tensor object is 张量运算索引索引是项目在序列中位置的数字表示。这个序列可以引用很多东西一个列表、一个字符串或任意的值序列。TensorFlow还遵循标准的Python索引规则这类似于列表索引或NumPy数组索引。关于索引的一些规则索引从零(0)开始。负索引(“-n”)值表示从末尾向后计数。冒号(“”)用于切片开始停止步骤。逗号(“”)用于达到更深层次。让我们用以下几行创建rank_1_tensorsingle_level_nested_list [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]rank_1_tensor tf.constant(single_level_nested_list)print(rank_1_tensor)Output: tf.Tensor([ 0 1 2 3 4 5 6 7 8 9 10 11], shape(12,), dtypeint32)测试一下我们的规则123# 规则1索引从0开始print(First element is:, rank_1_tensor[0].numpy())# 规则2负索引print(Last element is:, rank_1_tensor[-1].numpy())# 规则3切片print(Elements in between the 1st and the last are:, rank_1_tensor[1:-1].numpy())Output: First element is: 0 Last element is: 11 Elements in between the 1st and the last are: [ 1 2 3 4 5 6 7 8 9 10]现在让我们用以下代码创建rank_2_tensortwo_level_nested_list [ [0, 1, 2, 3, 4, 5], [6, 7, 8, 9, 10, 11] ]rank_2_tensor tf.constant(two_level_nested_list)print(rank_2_tensor)Output:tf.Tensor( [[ 0 1 2 3 4 5] [ 6 7 8 9 10 11]], shape(2, 6), dtypeint32)并用几个例子来测试第4条规则print(The 1st element of the first level is:, rank_2_tensor[0].numpy())print(The 2nd element of the first level is:, rank_2_tensor[1].numpy())# 规则4, 逗号代表进入更深层print(The 1st element of the second level is:, rank_2_tensor[0, 0].numpy())print(The 3rd element of the second level is:, rank_2_tensor[0, 2].numpy())Output: The first element of the first level is: [0 1 2 3 4 5] The second element of the first level is: [ 6 7 8 9 10 11] The first element of the second level is: 0 The third element of the second level is: 2现在我们已经介绍了索引的基本知识让我们看看我们可以对张量进行的基本操作。张量基本运算你可以轻松地对张量进行基本的数学运算例如加法元素乘法矩阵乘法求最大值或最小值找到Max元素的索引计算Softmax值让我们看看这些运算。我们将创建两个张量对象并应用这些操作。a tf.constant([[2, 4], [6, 8]], dtypetf.float32)b tf.constant([[1, 3], [5, 7]], dtypetf.float32)我们可以从加法开始。# 我们可以使用 tf.add() 函数并将张量作为参数传递。add_tensors tf.add(a,b)print(add_tensors)Output:tf.Tensor( [[ 3. 7.] [11. 15.]], shape(2, 2), dtypefloat32)乘法# 我们可以使用 tf.multiply() 函数并将张量作为参数传递。multiply_tensors tf.multiply(a,b)print(multiply_tensors)Output:tf.Tensor( [[ 2. 12.] [30. 56.]], shape(2, 2), dtypefloat32)矩阵乘法# 我们可以使用 tf.matmul() 函数并将张量作为参数传递。matmul_tensors tf.matmul(a,b)print(matmul_tensors)Output:tf.Tensor( [[ 2. 12.] [30. 56.]], shape(2, 2), dtypefloat32)注意Matmul操作是深度学习算法的核心。因此尽管你不会直接使用matmul但了解这些操作是至关重要的。我们上面列出的其他操作示例# 使用 tf.reduce_max() 和 tf.reduce_min() 函数可以找到最大值或最小值print(The Max value of the tensor object b is:, tf.reduce_max(b).numpy())# 使用 tf.argmax() 函数可以找到最大元素的索引print(The index position of the max element of the tensor object b is:, tf.argmax(b).numpy())# 使用 tf.nn.softmax函数计算softmaxprint(The softmax computation result of the tensor object b is:, tf.nn.softmax(b).numpy())Output:The Max value of the tensor object b is: 1.0 The index position of the Max of the tensor object b is: [1 1] The softmax computation result of the tensor object b is: [[0.11920291 0.880797 ] [0.11920291 0.880797 ]]操纵形状就像在NumPy数组和pandas数据帧中一样你也可以重塑张量对象。这个变形操作非常快因为底层数据不需要复制。对于重塑操作我们可以使用tf.reshape函数# 我们的初始张量a tf.constant([[1, 2, 3, 4, 5, 6]])print(The shape of the initial Tensor object is:, a.shape)b tf.reshape(a, [6, 1])print(The shape of the first reshaped Tensor object is:, b.shape)c tf.reshape(a, [3, 2])print(The shape of the second reshaped Tensor object is:, c.shape)# 如果我们以shape参数传递-1那么张量就变平坦化。print(The shape of the flattened Tensor object is:, tf.reshape(a, [-1]))Output:The shape of our initial Tensor object is: (1, 6) The shape of our initial Tensor object is: (6, 1) The shape of our initial Tensor object is: (3, 2) The shape of our flattened Tensor object is: tf.Tensor([1 2 3 4 5 6], shape(6,), dtypeint32)如你所见我们可以很容易地重塑我们的张量对象。但要注意的是在进行重塑操作时开发人员必须是合理的。否则张量可能会混淆甚至会产生错误。所以小心点.广播当我们尝试使用多个张量对象进行组合操作时较小的张量可以自动伸展以适应较大的张量就像NumPy数组一样。例如当你尝试将标量张量与秩2张量相乘时标量将被拉伸以乘以每个秩2张量元素。参见以下示例m tf.constant([5])n tf.constant([[1,2],[3,4]])print(tf.multiply(m, n))Output:tf.Tensor( [[ 5 10] [15 20]], shape(2, 2), dtypeint32)多亏了广播在对张量进行数学运算时你不必担心大小匹配。张量的特殊类型我们倾向于生成矩形的张量并将数值存储为元素。但是TensorFlow还支持不规则或特殊的张量类型这些类型包括参差不齐的张量字符串张量稀疏张量让我们仔细看看每一个都是什么。参差不齐的张量参差不齐张量是沿着尺寸轴具有不同数量元素的张量可以构建不规则张量如下所示ragged_list [[1, 2, 3],[4, 5],[6]]ragged_tensor tf.ragged.constant(ragged_list)print(ragged_tensor)Output:字符串张量字符串张量是存储字符串对象的张量。我们可以建立一个字符串张量就像你创建一个普通的张量对象。但是我们将字符串对象作为元素而不是数字对象传递如下所示string_tensor tf.constant([With this, code, I am, creating a String Tensor])print(string_tensor)Output:tf.Tensor([bWith this bcode, I am bcreating a String Tensor], shape(3,), dtypestring)稀疏张量最后稀疏张量是稀疏数据的矩形张量。当数据中有空值时稀疏张量就是对象。创建稀疏张量有点耗时应该更主流一些。这里有一个例子sparse_tensor tf.sparse.SparseTensor(indices[[0, 0], [2, 2], [4, 4]], values[25, 50, 100], dense_shape[5, 5])# 我们可以把稀疏张量转换成密集张量print(tf.sparse.to_dense(sparse_tensor))Output:tf.Tensor( [[ 25 0 0 0 0] [ 0 0 0 0 0] [ 0 0 50 0 0] [ 0 0 0 0 0] [ 0 0 0 0 100]], shape(5, 5), dtypeint32)结尾我们已经成功地介绍了TensorFlow的张量对象的基础知识。这应该会给你很大的信心因为你现在对TensorFlow框架的基本知识了解得更多了。
http://www.pierceye.com/news/729488/

相关文章:

  • 唐山市城市建设规划局网站大兴做网站公司
  • 陕西做网站的公司地址克拉玛依市住房和建设局网站
  • 做电影网站 广告收入怎么知道网站被k
  • 开发企业网站费用深圳宝安seo
  • 算命公司网站建设制作开发方案教育培训机构招生网站建设
  • 织梦做网站被告全椒网站建设
  • 安卓网站开发平台互联网工具型网站
  • 如何建设国外的网站联盟营销网站有哪些
  • 微信怎么创建微信公众号seo应该如何做
  • 北京php网站制作网站群建设思路
  • 企业建设网站的必要性小程序平台介绍怎么写
  • 网站界面设计应该遵循的原则贵州省住房和城乡建设厅网站报名网
  • 南昌建设医院官方网站国外做外链常用的网站
  • 淘宝店采用哪些方法做网站推广专门做网站的软件
  • 网站的ftp怎么查中国视觉设计网
  • 商城网站流量wordpress安装后做什么
  • 自己建网站要花多少钱wordpress采集发布接口
  • 个人网站做交易类的赚钱吗达人室内设计网论坛
  • 网站后台使用培训怎么样做微信公众号
  • 北京望京企业网站建设八佰yy影视
  • 在百度上做个网站需要多少钱创易网络
  • 网站建设神器帮人做网站犯法
  • 企业网站的特点是小程序开发文档微信小程序
  • 哈尔滨 建网站mvc做的网站如何发布访问
  • 江苏盐城网站开发百度快照首页
  • 中职网站建设课件青岛网站制作
  • 效果最好h5制作软件seo整站优化技术培训
  • 中国建设银行积分换购网站网站开发培训哪个好
  • 张家港网站建设培训wordpress电子报
  • 用dw制作学校网站教程网站优化排名方案