use dot product which increases speed

At the same time, it also consumes less memory