Open
Description
I posted some comments at https://fortran-lang.discourse.group/t/python-fortran-rosetta-stone-ported-from-fortran-90/5907/4
Here are some further comments.
The equivalence of NumPy fancy indexing and Fortran vector subscripts could be discussed. The Python
from numpy import array
a = array([10, 20, 30])
print(a[[0, 2]])
is equivalent to the Fortran
integer :: a(3)
a = [10, 20, 30]
print*,a([1, 3])
An alternative to the where
example in Fortran is a nested merge:
program main
implicit none
integer :: a(10), b(10)
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
where (a > 5)
b = a - 3
elsewhere (a > 2)
b = 1
elsewhere
b = 0
end where
print*,b
! lines below added by me
b = merge(a-3, merge(1, 0, a > 2), a > 5)
print*,b
end program main
Metadata
Metadata
Assignees
Labels
No labels