8000 torch.dot() doesn't match np.dot() behavior · Issue #38305 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content
torch.dot() doesn't match np.dot() behavior #38305
@ShairozS

Description

@ShairozS

I need to convert an image to grayscale on the fly within the forward method of my module. I noticed that the following code:

import numpy as np
img = np.random.random((96,96,3))
np.dot(img, [0.29, 0.58, 0.11])

works fine when completely in Numpy but when converted to Tensor form:

import torch
img = np.random.random((96,96,3))
torch.dot( torch.Tensor(img), torch.Tensor([0.29, 0.58, 0.11]))

it throws the error:

RuntimeError: 1D tensors expected, got 3D, 1D tensors at C:\w\1\s\tmp_conda_3.8_075429\conda\conda-bld\pytorch_1579852542185\work\aten\src\TH/generic/THTensorEvenMoreMath.cpp:733

I somewhat understand where this might come from, but I expected when the underlying arrays and tensors are the same dimensions, that broadcasting behavior would be the same? Can someone help me understand what's going on here?

cc @mruberry

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: numpyRelated to numpy support, and also numpy compatibility of our operatorstriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0