VFP: 3d arrays? - arrays

The following doesn't work... Can you do 3d arrays in foxpro?
DIMENSION sqlresults[10]
select list_code, count(donor) as ndine FROM cGift group by list_code INTO ARRAY sqlresults[1]
edit:
ah, a google search for "vfp multi-dimensional arrays" turned up something ("vfp 3d arrays" didn't)
Foxpro only supports 2d arrays. Guess i'll have to fake it with some substitution (&).

The only problem with your code is that you included a dimension in the query. Try this instead:
select list_code, count(donor) as ndine
FROM cGift
group by list_code
INTO ARRAY sqlresults
That said, on the whole, you're better off putting query results into a cursor than an array.

Sqlresults[1] = sys(2015)
Select ... into cursor (sqlresults[1])
This way your array holds names of the cursors, and you can access their values like:
Select (sqlresults[1])
?fieldname
Or use eval or &

Related

Multidimensional array BigQuery

In bigQuery is possible delcare an Array of Array like this
DECLARE ar2 ARRAY DEFAULT [['A','B','C'],['G','H','I'],['N','O','P']];
This syntax return error and I didn't find the right.
Seems that you need to work with array of arrays, if so the documentation says:
BigQuery does not support building arrays of arrays directly. Instead,
you must create an array of structs, with each struct containing a
field of type ARRAY
The page also gives a solution for that by using a array of structs. May something like:
DECLARE ar2 DEFAULT (
WITH words AS
(SELECT ['A','B','C'] as word
UNION ALL SELECT ['G','H','I'] as word
UNION ALL SELECT ['N','O','P'] as word)
SELECT ARRAY(
SELECT STRUCT(word)
FROM words)
AS all_words);
You can't have array of arrays on BigQuery. It does not support it. As per documentation about Declaring an ARRAY type shows:
ARRAY<ARRAY>
(not supported) This is an invalid type declaration which is included here just in case you came looking for how to create a multi-level ARRAY. ARRAYs cannot contain ARRAYs directly. Instead see the next example.
But there are workarounds for it, like using array with structs. Please see below code:
DECLARE TEST ARRAY<STRUCT<x ARRAY<STRING>,y ARRAY<STRING>,z ARRAY<STRING>>>
DEFAULT[(['A','B','C'],['E','F'],['W','X','Y','Z'])];
SELECT TEST;

Extracting arrays from array

I am currently working on machine learning, and as so I have an array in which the first column is the data and the second column is the label. Data was originally a cell array from Matlab (Not sure if that is important).
[My Array of arrays] https://i.stack.imgur.com/JFpWO.png
To make sure that everything is as it should be I would like to extract one of the arrays in index 0 and check its dimensions with the numpy.shape function. Currently, if I try that I just get the shape of the bigger array IE. (394,2)
Any ideas?
There are different ways.: Try..
arr[:,1,:]
or
arr[:,1]
or
[a[1] for a in arr]

VBA: splitting a two-dimensional array

In vba I have a two-dimensional array that I need to split somehow into two separate arrays. I have looked at the split function but I don't see how that would solve my problem.
The array looks like:
shift(1)
shift(1,1)
shift(1,2)
shift(1,3)
and so on...
Now, what I need is to split this like so:
shift(1)
shift(1,1)
shift(2)
shift (2,1) -- was shift(1,2)
shift (2,2) -- was shift(1,3)
What's the best way to do this?
Thanks for helping me out here!

Postgresql: dynamic slice notation for arrays

After reading this I wrote a naive attempt to produce this
col1
---------
1
4
7
from this
ARRAY[[1,2,3], [4,5,6], [7,8,9]]
This works
SELECT unnest((ARRAY[[1,2,3], [4,5,6], [7,8,9]])[1:3][1:1]);
But I in my case, I don't know the length of the outer array.
So is there a way to hack together the slice "string" to take into account this variability?
Here was my attempt. I know, it's a bit funny
_ids := _ids_2D[('1:' || array_length(_ids_2D, 1)::text)::int][1:1];
As you can see, I just want to create the effect of [1:n]. Obviously '1:3' ain't going to parse nicely into what the array slice needs.
I could obviously use something like the unnest_2d_1d Erwin mentions in the answer linked above, but hoping for something more elegant.
If you are trying to get the first element of all nested (2nd dimension) arrays inside an array (1st dimension) then you may use
array_upper(anyarray, 1)
to get all elements of a specific dimension
anyarray[1:array_upper(anyarray, 1)][<dimension num>:<dimension num>]
e.g, to get all elements of the first dimension
anyarray[1:array_upper(anyarray, 1)][1:1]
as in the code above. Please refer to PostgreSQL manual section on Arrays for more information.

Populating Multi dimensional array in octave/matlab to create waterfall plot in octave / matlab

I'm trying to create a Multi dimensional array so I can create a waterfall plot in octave, a matlab type of program. (Please note octave does not have the waterfall plot option so I have to make a work around.
I have multiple arrays that have frequency in the first column and amplitude in the second column.
example: When looped through the arrays, which are called sort_array they each need to be placed into a multidimensional array on a separate page.
4000, .5
3002, .1234
1093, .7
I was trying to have each of these arrays (sort_array) added to a single multidimensional array by using a for loop to have everything added to one array to make it easier to plot and export as a text file. I also thought using k as the page option for the multiple dimension array. But I keep getting dimensions mismatch. Any ideas how to fix this?
Please note I left out the sort_array code and just included the example array called sort_array above as an example of what the array would look like. There will be about 9000 of them.
md=[];
for k=1:9000
md_tmp=[sort_array(:,1),sort_array(:,2)]
ma(:,:,k)=[ma;ma_tmp];
end
So when I type in ma(:,:,1) I would get
4000, .5
3002, .1234
1093, .7
and if I type in ma(:,:,2) I would get the next one.
thanks
Your error is here: ma(:,:,k)=[ma;ma_tmp];
You are mixing up two concepts.
Either concatenate the new matrix onto the current one:
ma = [ma; ma_tmp];
OR
Assign the new matrix directly to the correct index (this is the cleaner, more efficient solution):
ma(:,:,k) = ma_tmp;
But you can't do both.
thanks I found a work around
sort_array=sortrows(arraytmp,-1); %sort by freq
k_tmp=repmat(k,length(sort_array(:,2)),1); %to create page for freq and amp in multidimensional array
ma_tmp=[sort_array(:,1),sort_array(:,2),k_tmp];
ma=[ma;ma_tmp];

Resources