COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Array Definition

• Email
• Follow

```How would you define the following array a=(/
1,2,13,1,2,13,1,2,13,1,2,13,../) if the repeating unit (/1,2,13/)
appears N times where N is known.
```
 0
Reply makis (6) 9/13/2010 10:13:50 AM

See related articles to this posting

```Hi Michael,

Michael wrote:
> How would you define the following array a=(/
> 1,2,13,1,2,13,1,2,13,1,2,13,../) if the repeating unit (/1,2,13/)
> appears N times where N is known.

I would type it out. You might be able to play silly burgers with
reshape (haven't thought how), but given the standard only allows up to
7 dimensional arrays N better be 0, 1 or 2, so typing it out would be
both not very long and clearer.

But what are you trying to do? I strongly suspect something to do with
derived types might be better, but given this info I can't guess what,

Ian
```
 0

```On 13/09/2010 8:13 PM, Michael wrote:
> How would you define the following array a=(/
> 1,2,13,1,2,13,1,2,13,1,2,13,../) if the repeating unit (/1,2,13/)
> appears N times where N is known.

program Oi_Terence_try_and_do_this_shorter_in_f77
implicit none
integer, parameter :: ru(3) = [1, 2, 13]   ! the repeating unit
integer, allocatable :: a(:)
integer :: i, n
write (*,"('Enter n:')")
a = [(ru, i = 1, n)]   ! F2003 allocate on assignment.
write (*, *) a         ! Replace with user defined operation on a...
end

```
 0

```Ian Bush wrote:
>
> Hi Michael,
>
> Michael wrote:
>> How would you define the following array a=(/
>> 1,2,13,1,2,13,1,2,13,1,2,13,../) if the repeating unit (/1,2,13/)
>> appears N times where N is known.
>
> I would type it out. You might be able to play silly burgers with
> reshape (haven't thought how), but given the standard only allows up to
> 7 dimensional arrays N better be 0, 1 or 2, so typing it out would be
> both not very long and clearer.
>
> But what are you trying to do? I strongly suspect something to do with
> derived types might be better, but given this info I can't guess what,
>

What a load of rubbish - Ignore this, I obviously can't read,

Ian
```
 0

```Michael wrote:
> How would you define the following array a=(/
> 1,2,13,1,2,13,1,2,13,1,2,13,../) if the repeating unit (/1,2,13/)
> appears N times where N is known.

Do you mean (/ (1,2,13,i=1,N) /) ?

```
 0

```Putting Michel's solution in a working program:

program blah
implicit none
integer, parameter :: N = 5
integer, parameter :: NR = 3
integer, parameter :: R(NR) = (/1,2,13/)
integer :: i
integer :: arr(N*NR) = (/ (R,i=1,N) /)
write(*,'(10i5)') arr
end program blah

lnx: gfortran blah.f90
lnx: a.out
1    2   13    1    2   13    1    2   13    1
2   13    1    2   13

cheers,

paulv

Michel Olagnon wrote:
> Michael wrote:
>> How would you define the following array a=(/
>> 1,2,13,1,2,13,1,2,13,1,2,13,../) if the repeating unit (/1,2,13/)
>> appears N times where N is known.
>
> Do you mean (/ (1,2,13,i=1,N) /) ?
>
```
 0

```"Michel Olagnon" <molagnon@ifremer-a-oter.fr> wrote in message
news:4C8E1993.3060508@ifremer-a-oter.fr...

> Michael wrote:

>> How would you define the following array a=(/
>> 1,2,13,1,2,13,1,2,13,1,2,13,../) if the repeating unit (/1,2,13/)
>> appears N times where N is known.

> Do you mean (/ (1,2,13,i=1,N) /) ?

I was considering the possibility that N might not be integral.
Solution:

--
write(*,*) transfer(0.64682312090346863D-153,(/'X'/));end

```
 0

```On Sep 13, 11:32=A0pm, "James Van Buskirk" <not_va...@comcast.net>
wrote:
> "Michel Olagnon" <molag...@ifremer-a-oter.fr> wrote in message
>
> news:4C8E1993.3060508@ifremer-a-oter.fr...
>
> > Michael wrote:
> >> How would you define the following array a=3D(/
> >> 1,2,13,1,2,13,1,2,13,1,2,13,../) if the repeating unit (/1,2,13/)
> >> appears N times where N is known.
> > Do you mean (/ (1,2,13,i=3D1,N) /) ?
>
> I was considering the possibility that N might not be integral.
> Solution:
>
>
> --
> write(*,*) transfer(0.64682312090346863D-153,(/'X'/));end

This does it too:

integer, parameter :: NUM =3D 3
integer :: n =3D NUM
integer, dimension (NUM*3) :: m
integer, dimension(3) :: source =3D [1, 2, 13]
!
m =3D reshape (spread (source, 2, n), [n * size (source, 1)])
!
print *, m
end

It's all a matter of taste and inclination :-)
Paul Thomas
```
 0

7 Replies
249 Views

Similar Articles

12/10/2013 10:00:40 PM
page loaded in 86717 ms. (0)

Similar Artilces:

looping through array of associative arrays
I'm trying to output the contents of an array of associative arrays in JavaScript. I'm looking for an equivalent of foreach in PHP. Example: var games = new Array(); var teams = new Array(); teams["team1"] = "Lakers"; teams["score1"] = "78"; teams["team1"] = "Sacramento"; teams["score2"] = "88"; games[0] = teams; var teams = new Array(); teams["team1"] = "Houston"; teams["score1"] = "94"; teams["team1"] = "Dallas"; teams["score2"] ...

Initialising an array with pointers into the same array.
Greetings, This is what I want to do: int a, b; int *arr[] = { &a, &b, &arr[1], }; Of course this won't work. Is there a (portable) way to achieve this? The application is initialising an array that is a linked list, and I don't want to do it at runtime as I am on an embedded system with not much memory. Regards TomH On 07/06/10 09:00, celephicus wrote: > Of course this won't work. Is there a (portable) way to achieve this? > The application is initialising an array that is a linked list, and I > don't want to do it at runtime as I am ...

Sorting problem with an Array of Arrays
Hi there, I have an array of arrays that looks like the following: arr1 = [["ABC-1", 1271768400, 2], ["ABC-2", 1271773800, 1], ["ABC-3", 1271863200, 2], ["ABC-4", 1271869200, 2], ["AAA-1", 1271862000, 2], ["DEF-1", 1271772000, 1]] Desired sort order: (1) label (1st element = all unique) (2) different labels (e.g. AAA, DEF) need to be inserted according to timestamp (2nd element), but maintain (1) label sort order; so AAA-2 can't come before AAA-1. (I don't have that data point here but it happens) => I ...

Updating single array element seems to send array out of kilter.
Hi all, Forgive me for my perl inadequacies, but hopefully it is a very simple solution that I am striving for. The pseudocode of what I am attempting to do is as follows: 1. Read contents of a file and parse data into 2 arrays - person and count. 2. Print out status of current arrays 3. Randomly choose one person from array 1 and increment the count by 1, updating the associated array element. 4. Print out new status of arrays. The issue I face is that the print in task 2 nicely places each entry on a single line, with no use of "\n". After running task 3, the print in task 4 no...

javascript arrays
Theres something very basic about javascript arrays I'm missing. The value of unit[i].value is 17.00 and value of the qty[i].value is 5 and I put these values into an array: myarray[unit[i].value]=qty[i].value; I accessed the qty[i].value by putting it into <div id='test2>: document.getElementById('test2').innerHTML+=myarray[unit[i].value]; and it says 5 so far so good. but this is undefined: document.getElementById('test2').innerHTML+=myarray[17.00]; why ? meltedown wrote: > Theres something very basic about javascript arrays I'm missing. > The v...

sorting arrays
I am hoping to improve on the technique for sorting values within an array (in a data step), which I implement using a macro. Is there a call or other non-macro solution to do this? Outputting the data and using proc sort is not an option. The program, whose purpose is to sort array B_ randomly, looks like this: Data testdata; Array a_ {*} a1-a7; Array b_ {*} b1-b7; Do i=1 to 7; A_(i)=ranuni(15151); B_(i)=I; End; Run; Data result; Set testdata; Array a_ {*} a1-a7; Array b_ {*} b1-b7; %sortaray(by=a_,others=b_); Run; ...

Query from array?
This is kind of funky. But the application uses what looks like these PIPE ROW functions and uses that as a loop driver: FOR v_rec IN (SELECT * FROM TABLE(data_list_functions.pipe_data_list_100()) WHERE rownum <= 100) LOOP At any rate, what I need to do is the reverse of what one would normally do. I need to remove all records from a given table that do NOT exist in this array above. So the record set returned contains new / old records to be added / deleted. But records in the table that are not in the array, those need to be removed. Any thoughts? It's kind of...

Definition of Production
Hi all, I'm looking for a clear definition of `production' in a (computer) grammatic/syntactic context. I've seen it used to mean anything from rule (in the xBNF sense) to input string, to mixtures of both (e.g. the segment of the input that matched a given rule). I would like to know if there is more precise definition, and an example or two if possible :). A related question is whether `production' == `production rule'. Thanks in advance for the help. Cheers, -Al- [No terms in comp sci have precise definitions, but I've consistently seen production used in the sens...

a definite integral and a workaround
I have posted some time ago a similar message but in view of the recent thread called "two integrals" here we go... In[1]:= \$Version Out[1]= "5.2 for Microsoft Windows (June 20, 2005)" I am interested in the integral In[2]:= Integrate[u*Sin[u*x]*Exp[(-y)*(Sqrt[1 + m^2*u^2]/m)], {u, 0, Infinity}, GenerateConditions -> False] Out[2]= Integrate[(u*Sin[u*x])/E^((Sqrt[1 + m^2*u^2]*y)/m), {u, 0, Infinity}, GenerateConditions -> False] I.e. it stays unevaluated within Mathematica (the same holds true for another CAS I tried). Say, In[6]:= in...

Showing an array of images
Greetings, I've got a cell of images (a pyramid) and I want to show it in a single window, though for(i=1:size_of_cell) subplot(1,size_of_cell,i), my_cell{i} end it draws the images scaled in size to match the smalles one. How could I make it retain for each image the original size? Moreover, using 'truesize' in imshow causes only one image to fit the window making the others disappear. Thanks in advance, Gav ...

help on an array problem
The following is my source code; ----------------------------------------------------------- library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity EGC is generic(M : natural := 4); Port ( input1 : in std_logic_vector(15 downto 0); output1 : out std_logic_vector(15 downto 0)); end EGC; architecture Behavioral of EGC is subtype vector16 is std_logic_vector(15 downto 0); type vector_M_16_Out is array(0 to M) of vector16; signal out1: vector_M_16_Out; begin out1(0) <= input1; proc0 : process(out1, input1) begin --o...

Variable Length Arrays
Dear all, I tried to search the web for this but was unable to locate anything useful. Any and all help will be much appreciated. Consider the following (useless for anything but illustration) source code fragment (presumably Fortran 95). subroutine S (N, A) integer, intent(in) :: N real, dimension(N), intent(in) :: A real, dimension(N) :: B ! (*) B = A / 2.0 write (*,*) size(A), ' => ', sqrt (sum (A * A)) write (*,*) size(B), ' => ', sqrt (sum (B * B)) end subroutine I am wondering if the declaration (...

FP array checksum?
I would like to generate a checksum for a small array of floating point numbers (to see if there was a change in or not in the array, without having to have all the original values in a form.) some sort of CRC would be nice. Any know of any sample code or suggestions? On Aug 7, 7:10=A0pm, la...@portcommodore.com wrote: > I would like to generate a checksum for a small array of floating > point numbers (to see if there was a change in =A0or not in the array, > without having to have all the original values in a form.) some sort > of =A0CRC would be nice. > > Any know of an...

IMAGE_STATISTICS for 3D Array
Hi, I am a beginner in IDL. I am stuck in finding out the image statistics using data of 3D array (sample, length, band). I used the following command to find out image statistics. ref_band = fltarr(s_size,l_size,7) ref_band = reflective_bands(nw_sam:nw_sam + roi_sam_size-1 , nw_lin:nw_lin + roi_len_size-1, band_no) maskgrid = fltarr(s_size,l_size,7) maskgrid(Grid_size*sregion +grid_sstart:Grid_size*sregion +Grid_size-1+grid_sstart,Grid_size*lregion +grid_lstart:Grid_size*lregion+Grid_size-1+grid_lstart,band_no)=1 ...

std::vector and array
Dear all, Could someone please let me know what is wrong with the following: #include <vector> int main() { typedef double (OriginType)[3]; std::vector< OriginType > OriginArray; // OriginArray.reserve( 1 ); OriginArray.resize( 1 ); // does not compile return 0; } this code does not compile using g++-4.4 Thanks ! On 01/02/2011 18:40, mathieu wrote: > Dear all, > > Could someone please let me know what is wrong with the following: > > #include<vector> > > int main() > { > typedef double (Origin...

efficient array question
I am using an array to simplify some programming code for numerous independent variables in a model. I am trying to create a flag variable marking records that have no missing data on any of the IVs (student and school). The following code shows the progress I've made thus far, but this code only evaluates each variable in the two macro vars studentl and school in isolation. Is there a way to alter this so it will evaluate whether a record is not missing information on ANY of the vars? So, if studentl contains gender and race, and school contains size and level, I wan...