mxnet随笔-broadcast,shape,ndim

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010255642/article/details/82053115
 # -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""
import mxnet as mx
import numpy as np

x = mx.nd.arange(0,3).reshape((1,3,1))
print x
y = x.broadcast_to((2,3,3))
print y


x = mx.nd.array([1, 2, 3, 4])
print x.ndim
x = mx.nd.array([[1, 2], [3, 4]])
print x.ndim
print y.shape

shape:形状

ndim:维度

broadcast:广播,但不改变维度
 

[[[0.]
  [1.]
  [2.]]]
<NDArray 1x3x1 @cpu(0)>

[[[0. 0. 0.]
  [1. 1. 1.]
  [2. 2. 2.]]

 [[0. 0. 0.]
  [1. 1. 1.]
  [2. 2. 2.]]]
<NDArray 2x3x3 @cpu(0)>
1
2
(2L, 3L, 3L)

猜你喜欢

转载自blog.csdn.net/u010255642/article/details/82053115