`
wang_peng1
  • 浏览: 3900876 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

tf.newaxis 和 numpy newaxis

 
阅读更多
n [71]: a1 = tf.constant([2,2], name="a1")

In [72]: a1
Out[72]: <tf.Tensor 'a1_5:0' shape=(2,) dtype=int32>

# add a new dimension
In [73]: a1_new = a1[tf.newaxis, :]

In [74]: a1_new
Out[74]: <tf.Tensor 'strided_slice_5:0' shape=(1, 2) dtype=int32>

# add one more dimension
In [75]: a1_new = a1[tf.newaxis, :, tf.newaxis]

In [76]: a1_new
Out[76]: <tf.Tensor 'strided_slice_6:0' shape=(1, 2, 1) dtype=int32>


>> x = np.arange(3)
>> x
array([0, 1, 2])
>> x.shape
(3,)

>> x[:, np.newaxis]
array([[0],
       [1],
       [2]])

>> x[:, None]
array([[0],
       [1],
       [2]])

>> x[:, np.newaxis].shape
 (3, 1)

 

分享到:
评论

相关推荐

    一文搞定 python 的广播机制与 np.newaxis

    先看看 np.newaxis 是啥, &gt;&gt;&gt; print(np.newaxis) None 佛了。。。 有啥用呢? &gt;&gt;&gt; data.shape (300, 2) &gt;&gt;&gt; data[:,np.newaxis].shape (300, 1, 2) &gt;&gt;&gt; data[np.newaxis,:].shape (1, 300, 2) 比较管用的是 data...

    numpy给array增加维度np.newaxis的实例

    如下所示: a[:, np.newaxis] # 给a... 您可能感兴趣的文章:numpy:np.newaxis 实现将行向量转换成列向量np.newaxis 实现为 numpy.ndarray(多维数组)增加一个轴numpy添加新的维度:newaxis的方法numpy np.newaxis 的实用

    numpy np.newaxis 的实用分享

    np.newaxis 在使用和功能上等价于 None,其实就是 None 的一个别名。 1. np.newaxis 的实用 &gt;&gt; x = np.arange(3) &gt;&gt; x array([0, 1, 2]) &gt;&gt; x.shape (3,) &gt;&gt; x[:, np.newaxis] array([[0], [1], [2]]) &gt;&gt; x[:, ...

    np.newaxis 实现为 numpy.ndarray(多维数组)增加一个轴

    np.newaxis 在使用和功能上等价于 None,查看源码发现:newaxis = None,其实就是 None 的一个别名。 1. np.newaxis 的实用 &gt;&gt; x = np.arange(3) &gt;&gt; x array([0, 1, 2]) &gt;&gt; x.shape (3,) &gt;&gt; x[:, np.newaxis] array...

    在TensorFlow中实现矩阵维度扩展

    用法很简单,在要扩展的维度上加上tf.newaxis就行了。 foo = tf.constant([[1,2,3], [4,5,6], [7,8,9]]) print(foo[tf.newaxis, :, :].eval&#40;&#41;) # =&gt; [[[1,2,3], [4,5,6], [7,8,9]]] print(foo[:, tf....

    numpy:np.newaxis 实现将行向量转换成列向量

    np.newaxis 新增一个轴 如何将数组[0,1,2]转换成列向量 用ndarray[: , np.newaxis] 代码实质就是将原本的(0,1,2)移到行上,然后新增一列 其实可以更简单 ndarray.shape=(3,1) &gt;&gt; x = np.arange(3) &gt;&gt; x array([0,...

    numpy添加新的维度:newaxis的方法

    np.newaxis放的位置不同,产生的新数组也不同 一维数组 x = np.random.randint(1, 8, size=5) x Out[48]: array([4, 6, 6, 6, 5]) x1 = x[np.newaxis, :] x1 Out[50]: array([[4, 6, 6, 6, 5]]) x2 = x[:, np....

    tensorflow模型的save与restore,及checkpoint中读取变量方式

    x = np.linspace(-1, 1, 100)[:, np.newaxis] #shape(100,1) noise = np.random.normal(0, 0.1, size=x.shape) y = np.power(x, 2) + noise #shape(100,1) + noise tf_x = tf.placeholder(tf.float32, x.shape) #...

    PyPI 官网下载 | fem-0.0.44.tar.gz

    资源来自pypi官网。 资源全名:fem-0.0.44.tar.gz

    numpy学习(三)

    numpy学习三 import numpy as np a=np.array([1,1,1]) b=np.array([2,2,2]) #vertical 合并 即上下合并 ...a[:,np.newaxis] array([[1], [1], [1]]) a[np.newaxis,:] array([[1, 1, 1]]) np

    使用TensorFlow实现简单线性回归模型

    X = np.linspace(-1, 1, n)[:,np.newaxis] # 等差数列构建X,[:,np.newaxis]这个是shape,这一行构建了一个n维列向量([1,n]的矩阵) noise = np.random.normal(0, 0.5, X.shape) # 噪声值,与X同型

    prism:Dan Foreman-Mackey的triangle.py的动画环绕

    import numpy as np import prism nsteps , nwalkers , ndim = 100 , 5000 , 5 samples = np . random . randn ( nsteps * nwalkers * ndim ). reshape ([ nsteps , nwalkers , ndim ]) # Make-believe burn in ...

    python Tensor和Array对比分析

    如下所示: 区别 Array ...image[np.newaxis, :] tf.expand_dims(image,axis=0) 数组拼接 np.concatenate([image, image], axis=0) tf.concat([frame,frame],axis=0) 相互转换 image.eval

    Numpy——数组合并

    文章目录1.np.vstack()2.np.hstack()3.np.newaxis()4.综合newaxis、vstack、hstack5.np.concatenate() 1.np.vstack() 对于一个array的合并,我们可以想到按行、按列等多种方式进行合并。 import numpy as np A = np....

    newaxis.ipynb

    newaxis.ipynb

Global site tag (gtag.js) - Google Analytics