Understanding PyTorch einsum

Since the description of einsum is skimpy in torch documentation, I decided to write this post to document, compare and contrast how torch.einsum() behaves when compared to numpy.einsum(). Differences: NumPy allows both small case and capitalized letters [a-zA-Z] for the “subscript string” whereas PyTorch allows only the small case letters [a-z]. NumPy accepts nd-arrays, plain … Read more

Difference between tensor.permute and tensor.view in PyTorch?

Input In [12]: aten = torch.tensor([[1, 2, 3], [4, 5, 6]]) In [13]: aten Out[13]: tensor([[ 1, 2, 3], [ 4, 5, 6]]) In [14]: aten.shape Out[14]: torch.Size([2, 3]) torch.view() reshapes the tensor to a different but compatible shape. For example, our input tensor aten has the shape (2, 3). This can be viewed as … Read more

Efficient element-wise multiplication of a matrix and a vector in TensorFlow

The simplest code to do this relies on the broadcasting behavior of tf.multiply()*, which is based on numpy’s broadcasting behavior: x = tf.constant(5.0, shape=[5, 6]) w = tf.constant([0.0, 1.0, 2.0, 3.0, 4.0, 5.0]) xw = tf.multiply(x, w) max_in_rows = tf.reduce_max(xw, 1) sess = tf.Session() print sess.run(xw) # ==> [[0.0, 5.0, 10.0, 15.0, 20.0, 25.0], # … Read more

TensorFlow: Max of a tensor along an axis

The tf.reduce_max() operator provides exactly this functionality. By default it computes the global maximum of the given tensor, but you can specify a list of reduction_indices, which has the same meaning as axis in NumPy. To complete your example: x = tf.constant([[1, 220, 55], [4, 3, -1]]) x_max = tf.reduce_max(x, reduction_indices=[1]) print sess.run(x_max) # ==> … Read more

How to understand the term `tensor` in TensorFlow?

TensorFlow doesn’t have first-class Tensor objects, meaning that there are no notion of Tensor in the underlying graph that’s executed by the runtime. Instead the graph consists of op nodes connected to each other, representing operations. An operation allocates memory for its outputs, which are available on endpoints :0, :1, etc, and you can think … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)