I have two numbers [739 560] and I just want to know if it appears in a huge 2D array of size 9000x2
I cannot find a simple way of checking that.
Can anyone suggest anything simple? Thanks
You can do:
find(ismember(A, r, 'rows'))
Related
It is true that we have to use 10 'for loops' for a 10-D array. But I wonder if there is any other idea to process any dimensional array with less than that much for loops. I need an idea just to get input and print that output for multidimensional array in C/Java. eg: a[3][3][3][3][3][3][3][3][3][3]. Please provide some code if possible.
Thank You!
I currently have a MATLAB range j=1:200 and an array m=96:106.
I'm trying to define a new array that will have all the values in j that aren't in m.
I've tried using
j_prime = (j~=m)
but that doesn't work for a range of numbers. If m was just a number like 101, this works. I'm sure I just don't know MATLAB enough to know a good way of doing this.
Just found the setdiff command so using setdiff(j,m) will result in what I'm looking for!
i am using octave for my project as i cant afford a matlab license, however i have run into a significant roadblock and that is the lack of associative array data structures.
my problem is this:
i have some data in the form of cell arrays containing matrices with each cell array representing a potential solution to a problem. i also have a floating point number that represents the evaluated performance of that solution which i want to put into a map-like data structure with the floating point score as the key, in order to sort the solutions by their performance.
can anyone suggest a simple solution to this problem?
what i have thought about doing so far is making each element part of a two element cell array, with the evaluation score as the first element and the data as the second, and then put those arrays into another cell array, which i then apply some sorting algorithm to, sorting by array{i}{1}.. but this seems like a pretty clunky solution.
does octave have any functionality in this respect that i am just unaware of? or is my clunky solution the only way to achieve this?
any help would be greatly appreciated
thanks
How about keeping the cell array as it is, but create a matrix where the columns are the evaluation score and the index into the cell array. Then you can easily use sortrows on the evaluation score column and use the index to pull the solution from the cell array. I think this should be a simple solution that has the benefit of not rearranging your potentially large set of data.
I have a pretty simple text file of just numbers that looks like
0
1.57
3.14
This example has 3 numbers, but amount is fine. I'm trying to read these into a 1d array of Float 64's, so I tried the following.
function read_x_data(fname)
f=open(fname)
xarr=readdlm(f, Float64)
print(xarr)
xarr=sortperm(xarr)
end
However, I get the error that sortperm has no matching method sortperm(::Array{Float64, 2}). I don't understand why this is happening- how can I read my data into a 1d array instead? I saw a similar question at Reading line by line in Julia, but I believe that using push n times like that is very inefficient, right? Any help with my problem or suggestions are much appreciated. Thanks!
To answer your immediate question: vec will reshape any array into a 1d vector.
sortperm returns the permutation but not the original data; hence your example, even if you added vec(xarr), would throw away the data. You probably want sort.
Finally, in Julia push! is not inefficient. You may be expecting it to be inefficient from experience with another language (Matlab?), but in Julia you can efficiently grow 1d arrays.
If your intention is to sort the data, this might work for you.
read_x_data(fname) = sort!(vec(readdlm(fname,Float64)))
I have a 3D array of int values and I want to search just through one of the subarrays for a specific value. While I could for-loop my way through every possible combination of the below code.
array[numberIwant][1-255[1-255];
That seems like overkill. I've come across the foreach type of for and thought that might be the answer to my quest but either it's not or I don't understand it well enough to get it to work. Could anyone suggest the way this should be done?
The foreach and the for loop will have almost identical processing time for an array of that size.
Although it might seem like overkill it is not, you will need to do a triple nested for loop then have an if statement seeing if the number you want was found.