How to Add a Vector to a 2D Array in Fortran 90?

  • Thread starter Thread starter dwnlder
  • Start date Start date
  • Tags Tags
    2d Array Vector
AI Thread Summary
In Fortran 90, adding a vector to each column of a 2D array can be streamlined without using bulky do loops. Instead of the traditional loop approach, which iterates through each column, you can utilize array operations for a more concise solution. The expression a(:, :) = a(:, :) + b(:) is not directly valid for this operation, as it attempts to add the vector to the entire array at once. A more efficient method is to use the intrinsic 'reshape' function or broadcasting techniques, which allow for element-wise addition without explicit loops. Additionally, creating a custom function or operator can simplify this process further, enhancing code readability and efficiency.
dwnlder
Messages
1
Reaction score
0
hi. i have a quick question regarding fortran 90. i often need to add a vector to a 2d dimensional array, and i find it a bit to 'bulky' to always use do loops.

let's say i have this:
Code:
do i=1, 20
   a(:, i)=a(:, i)+b(:)
end do

is there a simple(r) way to tell fortran that i want to add the values to the 'first' value of the array? so i could use something as simple as
Code:
a(:, :)=a(:, :)+b(:)

thx in advance for the answers and suggestions.
 
Technology news on Phys.org
You could either write a quick FUNCTION or perhaps define a custom operator.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
20
Views
3K
Replies
4
Views
2K
Replies
2
Views
1K
Replies
2
Views
2K
Replies
3
Views
2K
Replies
13
Views
3K
Replies
11
Views
3K
Replies
25
Views
2K
Back
Top