Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rosetta Stone comments #290

Open
Beliavsky opened this issue Jun 3, 2023 · 0 comments
Open

Rosetta Stone comments #290

Beliavsky opened this issue Jun 3, 2023 · 0 comments

Comments

@Beliavsky
Copy link
Contributor

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 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant