I want to create a 3x3 array filled with tens.
I know for array filled with zeros or ones, i can use np.zeros() and np.ones(), respectively.
But what about an array filled with tens?
Are there no special ways to do this?
You can use np.fill() to fill an array with any value.
Related
i have one big bagOfWords array, and two bagOfWords arrays. vocabularies of two arrays are elements of the big array's vocabulary (meaning they are subsets of the big).
now i want to create an array that is, its first column must be big array's vocabulary, second column must be one of the two array's counts value for that row's vocabulary word, third column must be the other array's counts value for that row's vocabulary word. and if an array doesn't have a counts value for that row's vocabulary word then i want to make that index value 1.
how can i do this? i didn't find any function that converts bagofwords to cell array. and i'm not sure how to compare those arrays.
i can send you the variables but seems like i cannot upload them here.
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]
I am new to matlab. I have one question about datatypes.
I have an array of the cell array type. In the variables window it shows me it as 190x1 double.
I have two questions.
What is the purpose of the cell array type if there is the matrix type ?
How to append another similar array to the column of an existing array. For example I have two arrays 190x1 double I wan't a new array to be 380x1 double
I would be grateful for any help.
Thanks
I'd encourage you to browse the documentation for cell arrays. One of the most common uses as it states is mixed size or mixed type data...among other uses.
Cell arrays commonly contain either lists of text strings,
combinations of text and numbers, or numeric arrays of different
sizes.
To append two arrays you could do this. It will place the two vectors end to end.
X=ones(190,1);
X =[X; X];
I have a 60x60x35 array and would like to calculate the Wilcoxon signed rank test to calculate if the median for each element value across the third array dimension (i.e. with 35 values) is different from zero. Thus, I would like my results in two 60x60 arrays - with values of 0 and 1 depending on the test statistic, and in a separate array with corresponding p values.
The problem I am facing is specifying the command in a way that desired output would have appropriate dimensions and would be calculated across the appropriate dimension of the array.
Thanks for your help and all the best!
So one way to solve your problem is using a nested for-loop. Lets say your data is stored in data:
data=rand(60,60,35);
size_data=size(data);
p=zeros(size_data(1),size_data(2));
p(:,:)=NaN;
h=zeros(size_data(1),size_data(2));
h(:,:)=NaN;
for k=1:size_data(1)
for l=1:size_data(2)
tmp_data=data(k,l,:);
tmp_data=reshape(tmp_data,1,numel(tmp_data));
[p(k,l), h(k,l)]=signrank(tmp_data);
end
end
What I am doing is I preallocate the memory of p,h as a 60x60 matrix. Then I set them to NaN, so if you can easily see if sth went wrong (0 would be an acceptable result). Now I loop over all elements and store the actual data array in a new variable. signrank needs the data to be an array so I reshape it to two dimensions.
I guess you could skip those loops by using bsxfun
I have an 3 dimensional array that represents an xy grid, and the z vector represents depth. I only know depths of certain rows and am trying to interpolate the array. My questions is how do I create a 720x400 array, without setting all the values to 0 (as that could affect the interpolation).
Thanks!
You can use:
A = nan(m,n,...);
to initialize a matrix with NaN's, if that is what you ask for. Other popular choices are inf(m,n,...) to initialize with Inf's and ones(m,n,...) to initialize with 1's.
So, to create a 720x400 matrix full of NaN's you can just:
A = nan(720,400);
It is not necessary to initialize the empty rows to a special value. Instead, you can modify the interpolation procedure to assign a zero weight to these rows. Then, they will not affect the interpolation.
A simple way to do so in MATLAB would be to use the griddata method for the interpolation.