1

could someone explain me the difference in the List size? Once it is (x,1) and the other (x,). I think I get an idexError due to that.

Thanks enter image description here

print(Annotation_Matrix) [array([[1], ..., [7], [7], [7]], dtype=uint8)] print(idx) [array([ True, True, True, ..., False, False, False], dtype=bool)] 

p.s. the left one is created with

matlabfile.get(...) 

the right one with

in1d(...) 
7
  • can you post a print() of the lists? like a snippet? A good way to avoid this error is to loop through iterables (lists, tuples, etc) like so: for item in iterable: or for i, item in enumerate(iterable): if you need the indexes. This lets python handle the amount if iterations according to the iterable size. Commented Jun 29, 2016 at 11:15
  • 1
    Thanks for your answer. I actually don`t have a problem with getting the indices, but later in the code I use: a=[val[idx[sb],:] for sb, val in enumerate(idx) if sb in range(len(c))] . Here I get the error: IndexError: too many indices for array. I think that is due to the different size representation. Commented Jun 29, 2016 at 11:26
  • 1
    Addition: I only get the error if I use idx (right List) in enumerate but not if I use Annotatio_Matrix (left List) Commented Jun 29, 2016 at 11:34
  • well, a = [val[idx[sb],:] for sb, val in enumerate(idx) if sb in range(len(c))] does not make much sense.. ☺ first of all, idx[sb] = val since val are the items of idx and sb is the index. Can you do val[val] ? Probably not. Commented Jun 29, 2016 at 11:35
  • 1
    True that. I reused this from before where I needed to reach certain rows in matrices where the matrices where list elements. Now I just want to hand the values from. AS you are right I have to use Annotation_Matrix, as the values are stored in Annotation_Matrix while idx are the indices of Annotation_Matrix I want ot hand over to a. Commented Jun 29, 2016 at 11:43

1 Answer 1

1

An array A of size (x,1) is a matrix of x rows and 1 columns (2 dimensions), which differs from A.T of size (1,x). They have the same elements but in different 'orientation'. An array B of size (x,) is a vector of x coordinates (1 dimension), without any orientation (it's not a row nor a column). It's just a list of elements.

In the first case, one can access an element with A[i,:] which is the same of A[i,0] (because it has only one column). In the later, the call B[i,:] causes an error because the array B has only one dimension. The correct call is B[i].

I hope this helps you to solve the problem.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks a lot for your answer. To make it 100% clear numpy write (x,1) as only (x,)? As seen in the right picture. But what is then the difference to the left prictrue which says (x,1)?
Numpy manages both types of arrays: two dimensionals (x,1) and one dimensionals (x,). This is a difference with MATLAB or Octave, in which all are matrices (in this case, only (x,1)).
Ahhh, Cheers for info. If I use idx=[transpose(idx[sb])for sb in range(len(selected_babies))] it actually doesnt change. Shouldnt it?
In this case, I don't know what are you doing because I don't see all the variables, but "transposing a 1-D array returns an unchanged view of the original array", as is noted here.
mm. Ok. In Matlab transposing a=a' changes a array form (x,1) to (1,x)
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.