Multi-Dimensional array multiplication in fortran

Click For Summary

Discussion Overview

The discussion centers on the topic of multi-dimensional array multiplication in Fortran, specifically addressing how to perform such operations beyond two dimensions. Participants explore the mathematical definitions and programming approaches related to this concept.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant inquires about multi-dimensional array multiplication in Fortran, providing an example of arrays A(5,5,3,3) and B(5,5,3,3).
  • Another participant questions whether the inquiry pertains to matrix multiplication (2D) or higher dimensions, referencing APL's approach to multi-dimensional operations.
  • A participant clarifies that they are indeed referring to more than two dimensions and describes how APL handles such multiplications by summing products of specific dimensions.
  • One participant expresses uncertainty about how to multiply matrices of more than two dimensions and suggests using Fortran's built-in functions for 2D matrices, proposing that looping might be necessary for higher dimensions.
  • Another participant raises a concern about the mathematical definition of such multiplications, implying that the approach may lack clarity or rigor.
  • A further contribution discusses APL's inner product operator, explaining its flexibility in handling arrays of various dimensions as long as certain size conditions are met.

Areas of Agreement / Disagreement

Participants express differing views on the feasibility and definition of multi-dimensional array multiplication, with no consensus reached on a specific method or understanding of the concept.

Contextual Notes

Participants highlight the need for clear mathematical definitions and the potential complexity involved in multi-dimensional operations, indicating that assumptions about dimensions and operations may vary.

selmayda
Messages
9
Reaction score
0
Hi;

Is there anyone who knows multi-dimensional array multiplication in fortan ?

such as;

A(5,5,3,3) * B(5,5,3,3)

thanks
 
Technology news on Phys.org
selmayda said:
Is there anyone who knows multi-dimensional array multiplication in fotran?
Do you mean matrix multiplication, which is 2 dimensions for each variable, or more than 2 dimensions? In the case of a programming language called APL, a generic form of matrix like operations is performed on the last dimension of the left variable and the first dimension of the second variable.
 
I mean more than 2 dimensions.
 
selmayda said:
I mean more than 2 dimensions.
Using APL as an example, and using the names "table" to mean the first dimension, "column" to mean the second dimension, and "row" to mean the last dimension, then "rows" of numbers from the left variable are multiplied with "tables" of numbers from the right variable, and the products summed to produce the output variable. The last dimension of the left variable and the first dimension of the right variable must be the same size, the sizes of the other dimensions don't matter. For example, you could "multiply" A(2,3,4) with B(4,5,6), and the resulting output would have size (2,3,5,6). I'm not sure why you'd want to do this.
 
I have never known how to multiply matrices of more than 2 dimensions each...how do you that?

For two 2-d matrices at a time, Fortran does provide dot_product() and matmul(), read up.

Other than that, maybe you are trying to take too much of a shortcut for what you want to do...is ...how about you do some looping and reduce the problem?


Germán
 
More importantly, how do you define mathematically such a multiplication? It sounds like you want to throw a bunch of numbers at a program and are hoping the program will properly sort everything out.
 
SteamKing said:
More importantly, how do you define mathematically such a multiplication?
This was done in the programming language APL, which treats matrix multplies as a specific case of it's "inner product" operator. For a matrix multiply, the syntax is:

A +.× B

but this is allowed for A and B of any number of dimensions as long as the size of the last dimension of A equals the size of the first dimension of B. If A and B are vectors, then the result is the dot product (inner product) of two vectors. APL's inner product operator is more generic, to compare strings, you could use:

A ^.= B

Where ^ means binary AND, and = means compare (outputs 0 or 1). If A and B are 2 dimensional matrices, then the result produces a 1 for each row of A that equals a column of B (otherwise it produces a 0), but this will also work for vectors or for A and B of greater than 2 dimensions. B needs to be transposed so that it's first dimension contains the strings. There's a unary operator to do this.
 
Last edited:

Similar threads

  • · Replies 20 ·
Replies
20
Views
3K
  • · Replies 20 ·
Replies
20
Views
4K
Replies
64
Views
11K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
8K
  • · Replies 14 ·
Replies
14
Views
5K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K