dot-product

Does np.dot automatically transpose vectors?

荒凉一梦 提交于 2019-12-10 17:48:53
问题 I am trying to calculate the first and second order moments for a portfolio of stocks (i.e. expected return and standard deviation). expected_returns_annual Out[54]: ticker adj_close CNP 0.091859 F -0.007358 GE 0.095399 TSLA 0.204873 WMT -0.000943 dtype: float64 type(expected_returns_annual) Out[55]: pandas.core.series.Series weights = np.random.random(num_assets) weights /= np.sum(weights) returns = np.dot(expected_returns_annual, weights) So normally the expected return is calculated by (x1

How to get the Fortran SUM command result to exceed 2^24 for single precision arrays

こ雲淡風輕ζ 提交于 2019-12-10 15:52:37
问题 To check memory allocations we populate single precision arrays with unit values and interrogate with the SUM and DOT_PRODUCT commands. These intrinsics stop counting after 16777216 (= 2^24). How can we get these commands to count billions of elements? We prefer to avoid DO loops. This is not a problem with higher precision arrays. program allocator use iso_fortran_env implicit NONE integer, parameter :: sp = selected_real_kind ( REAL32 ) integer, parameter :: xlint = selected_int_kind (

Calculating column-wise dot product between two matrices

☆樱花仙子☆ 提交于 2019-12-08 04:37:25
问题 I would like to determine the dot product between the i th column in one matrix and the i th column in a second matrix. The end result will be an array containing i dot products. Here is a reproducible example of what I want to do: #Generate two matrices with 10 columns each with 5 rows (thus i in this case is 10) m1 <- replicate(10, rnorm(5)) m2 <- replicate(10, rnorm(5)) #Inefficiently calculate dot product of ith column in m1 with ith column in m2 d1 <- t(m1[,1]) %*% m2[,1] d2 <- t(m1[,2])

3D space: following the direction that an object is pointing towards, using the mouse pointer

佐手、 提交于 2019-12-05 17:54:41
Given the 3D vector of the direction that the camera is facing and the orientation/direction vector of a 3D object in the 3D space, how can I calculate the 2-dimensional slope that the mouse pointer must follow on the screen in order to visually be moving along the direction of said object? Basically I'd like to be able to click on an arrow and make it move back and forth by dragging it, but only if the mouse pointer drags (roughly) along the length of the arrow, i.e. in the direction that it's pointing to. thank you Dr. ABT I'm not sure I 100% understand your question. Would you mind posting

Is there alternative for imread command to reduce delay in matlab program?

社会主义新天地 提交于 2019-12-04 05:56:48
问题 I am having 2900 images in this path G:\newdatabase\ It is taking too much time to read images.For dot product also it is taking too much time. Questions: 1.Is there any alternative for imread command which increases performance? 2.Is there any alternative for dot command which increases performance? Source code i tried: srcFiles = dir('G:\newdatabase\*.jpg'); % the folder in which ur images exists for b = 1 : length(srcFiles) filename = strcat('G:\newdatabase\',srcFiles(b).name); Imgdata =

ValueError: matrices are not aligned for copy error and x[:]

与世无争的帅哥 提交于 2019-12-04 05:46:39
问题 I got the ValueError as given below. ValueError: matrices are not aligned for copy error It was traced to the following line (I did not write this code, I am trying to use it): x1[:] = _dotproduct(x1, u) The dot product is like numpy dot product, it works FINE, printing _dotproduct(x1, u) give a valid answer. It is x1[:] that is not working. What does [:] mean? I have never seen that. Also how can I solve the error of alignment? Edit: I have now traced the error to x1[:] , so instead of this

Matlab: Argmax and dot product for each row in a matrix

时光总嘲笑我的痴心妄想 提交于 2019-12-04 04:10:13
问题 I have 2 matrices = X in R^(n*m) and W in R^(k*m) where k<<n . Let x_i be the i-th row of X and w_j be the j-th row of W. I need to find, for each x_i what is the j that maximizes <w_j,x_i> I can't see a way around iterating over all the rows in X, but it there a way to find the maximum dot product without iterating every time over all of W? A naive implementation would be: n = 100; m = 50; k = 10; X = rand(n,m); W = rand(k,m); Y = zeros(n, 1); for i = 1 : n max_ind = 1; max_val = dot(W(1,:),

How is convolution done with RGB channel?

半世苍凉 提交于 2019-12-03 23:49:46
Say we have a single channel image (5x5) A = [ 1 2 3 4 5 6 7 8 9 2 1 4 5 6 3 4 5 6 7 4 3 4 5 6 2 ] And a filter K (2x2) K = [ 1 1 1 1 ] An example of applying convolution (let us take the first 2x2 from A) would be 1*1 + 2*1 + 6*1 + 7*1 = 16 This is very straightforward. But let us introduce a depth factor to matrix A i.e., RGB image with 3 channels or even conv layers in a deep network (with depth = 512 maybe). How would the convolution operation be done with the same filter ? A similiar work out will be really helpful for an RGB case. They will be just the same as how you do with a single

numpy: column-wise dot product

做~自己de王妃 提交于 2019-12-03 11:40:25
问题 Given a 2D numpy array, I need to compute the dot product of every column with itself, and store the result in a 1D array. The following works: In [45]: A = np.array([[1,2,3,4],[5,6,7,8]]) In [46]: np.array([np.dot(A[:,i], A[:,i]) for i in xrange(A.shape[1])]) Out[46]: array([26, 40, 58, 80]) Is there a simple way to avoid the Python loop? The above is hardly the end of the world, but if there's a numpy primitive for this, I'd like to use it. edit In practice the matrix has many rows and

dot product in python [closed]

回眸只為那壹抹淺笑 提交于 2019-12-03 06:51:35
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . Does this Python code actually find the dot product of two vectors? import operator vector1 = (2,3,5) vector2 = (3,4,6) dotProduct = reduce( operator.add, map( operator.mul, vector1, vector2)) 回答1: You can also