"perpendicular" element-wise multiplication of two 2D arrays to a 3D array - arrays

I want to multiply two 2D arrays element-wise "vertically" so that the resulting array is 3D:
Illustration
Is this possible without much trouble? Thanks in advance for help.
I googled and the only thing that might be purposeful but seems very laborious to me is numpy.reshape

Related

2D Math Matrix with Malloc

I know a similar question is already asked here for example:
Malloc a 2D array in C
However, my question is not how to create one but rather if I should prefer to use for a mathematical 2D matrix a "real" 2D array (with pointers of pointers) or rather a flattened 1-dimensional array with proper indexing.
I think the only case it can be important is when you are doing operations that depends on the neighbors of the matrix. In this case, using a 2D matrix is a bit better because it avoids cache misses.
This is specially important for problem solutions that use dynamic programming optimization .
I believe it can also be important for image processing, where many operations are applied in a rectangle of pixels.

Is there any Fortran function to transpose 3D array?

I need to transpose a 3D matrix in Fortran. I have a 3d array: V(111,222,333); I need to transpose it to V(333,111,222). Is there any function to do that in Fortran?
I hesitate to disagree with #IanBush and perhaps what follows is neither easy nor clear. The following statement will return a permutation of the array V. If I have got it right then the element at V(i,j,k) is sent to V_prime(k,i,j).
V_prime = RESHAPE(source=V, shape=[size(V,3),size(V,1),size(V,2)], order=[2,3,1])
Whether this creates the permutation OP asks for is a bit unclear, I'm not aware that there is a single definition of the transpose of an array of rank other than 2. Changing the order will produce different permutations.
This question is probably a duplicate of Fortran reshape - N-dimensional transpose. It is certainly worth reading the answers to that question which explain the use of reshape with order very well.
There is no routine that will do this simply. I would write some loops, that is often the easiest and clearest way.

VBA calculating with strings

I am quite new to vba coding. I have written a code which reads some data generates a matrix and a vector inverts the matrix and then multiples the inverted matrix with the vector, so nothing big. But now I want that the elements of the matrix and vector are strings or symbols. I hope that i will be able to get a more general solution. Is this somehow possible? Both objects are arrays.
The stringe i use do not have numerical values. In other words I am looking for a oppertunity to calculat with symbols like an algebra program like mathematica or maxia does.

Writing an efficient code for row-wise reshaping of multi-dimentsional array

I am converting my matlab code to C-code. I need to write a function for "reshaping" multi-dimensional array similar to "reshape" function in matlab who does it in "row-wise" manner.
Though I can write myself, I am cencerned that my method would be very inefficient, given I am not an expert C/C++ programmer. So, I am wondering if someone already have some efficient code and would be kind enugh to share.
I am looking for something similar to what has been done in Armadillo library (C++ library).
.reshape(n_rows, n_cols, dim=0) // For column-wise reshaping
.reshape(n_rows, n_cols, dim=1) // For row-wise reshaping
Does anyone know some lib in C doing similar?
Usually in Matlab I do the following operation to convert my 3D array and 4D array to equivalent 1D array in row-wise manner.
%Creating y_exp_1D_NoReg: 1D equivelent of 3D data
Temp = reshape(y_exp_3D,[sizeH*sizeV, LenTE]);
yexp1D_1 = (reshape(Temp',[sizeH*sizeV*LenTE, 1]));
%Creating y_exp_1D_NoReg: 1D equivelent of 4D data
Temp = reshape(y_exp_4D,[sizeZ*sizeH*sizeV,LenTE]);
yexp1D_2 = (reshape(Temp',[sizeZ*sizeH*sizeV*LenTE, 1]));
Also, for my C code, I have been using following libraries: Lapack, Blas, TAUCS
I could find an example here link; but this is in C# and hence not usable for me.

arithmetic operations with arrays of unequal size in matlab

I am attempting to calculate a 2D polar plot of the power pattern of an Archimedean spiral array of isotropic antennas in MATLAB. This requires a theta and phi array that are both different sizes.
The code I am using is as follows:
clear all
close all
clc
r=27000;
phi=0:.02:2*pi;
theta=0:.02:pi/2;
px=r.*cos(phi);
py=r.*sin(phi);
wL=1;
k=(2*pi)/wL;
d=px.*sin(theta).*cos(phi)+py.*sin(theta).*sin(phi);
phase=0;
psi=k.*d+phase;
N=27;
PowPatt=(sin(N.*(psi./2))./(N.*sin(psi./2))).^2;
polar(psi,PowPatt)
Naturally I get the following error:
??? Error using ==> times
Matrix dimensions must agree.
Error in ==> powerpattern at 11
d=px.*sin(theta).*cos(phi)+py.*sin(theta).*sin(phi);
Is there anyway to change my code to perform the arithmetic operations on the theta and phi arrays?
Thank you.
Patrick
The code itself doesn't work because theta and phi are different sizes. They need to be the same size to do the element-wise multiply ".*" operation. Or, they need to be compatible sizes to do a matrix-wise multiply "*". You don't have either, so your problem is not with the code but with your interpretation of the antenna array equations. We can't help you there.
I'm guessing that the array equations intend for you to either permute across all combinations of phi and theta so that you can then sum over one or more dimensions of phi and theta. Therefore, you're likely going to have to introduce a for loop and/or a sum() operation. Since I don't know your antenna array equations, I can't help. You'll have to go back and look at the physics. Once you understand the array antenna equations better, you'll be able to code them better.

Resources