문제

In Matlab the buffer of matrix is continuous in column . So what about the numpy array of Python. which one is beter between numpy.empty((n,1)) and numpy.empty((1,n))

도움이 되었습니까?

해결책

In numpy you can choose between Fortran-contiguous (along the column, like in Matlab) and C-contiguous (along the row, which is the default in numpy) order, passing the order argument when you create an array, so you have more flexibility.

As @user2357112 already said, for a 1xN or Nx1 array it does not matter, but for a MXN array it does matter and you should be aware of that.

다른 팁

They do different things. One makes an Nx1 array; the other makes a 1xN array. Neither is "better". (In fact, the memory layout will be identical for both arrays, even if you specify column-major storage.)

To answer the question about storage layout, though, numpy defaults to row-major layout, a.k.a. C-contiguous. You can see this clearly reflected in the docs.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top