2013/11/26 Peter Prettenhofer <peter.prettenho...@gmail.com>:
> Hi all,
>
> I'm currently modifying our tree code so that it runs on both fortran and c
> continuous arrays. After some benchmarking I got aware of the following
> numpy behavior that was contrary to what I was expecting::
>
>   >>> X = # some feature matrix
>   >>> X = np.asfortranarray(X)
>   >>> X.flags.f_contiguous
>   True
>   >>> # so far so good
>   >>> X_train = X[:1000]
>   >>> X_train.flags.f_contiguous
>   False
>   >>> X_train.flags.c_contiguous
>   False
>   >>> # damn - seems like a view is neither c nor fortran continuous

Only if you slice the rows of a fortran aligned 2D array, this is
expected. If you slices the rows of a C-contiguous 2D array or the
columns of a F-contiguous 2D array it stays contiguous.

>>> import numpy as np
>>> a_c = np.arange(12).reshape(3, 4)
>>> a_f = np.asfortranarray(a_c)
>>> a_c.flags
  C_CONTIGUOUS : True
  F_CONTIGUOUS : False
  OWNDATA : False
  WRITEABLE : True
  ALIGNED : True
  UPDATEIFCOPY : False
>>> a_f.flags
  C_CONTIGUOUS : False
  F_CONTIGUOUS : True
  OWNDATA : True
  WRITEABLE : True
  ALIGNED : True
  UPDATEIFCOPY : False
>>> a_c[1:].flags
  C_CONTIGUOUS : True
  F_CONTIGUOUS : False
  OWNDATA : False
  WRITEABLE : True
  ALIGNED : True
  UPDATEIFCOPY : False
>>> a_f[:, 1:].flags
  C_CONTIGUOUS : False
  F_CONTIGUOUS : True
  OWNDATA : False
  WRITEABLE : True
  ALIGNED : True
  UPDATEIFCOPY : False



-- 
Olivier
http://twitter.com/ogrisel - http://github.com/ogrisel

------------------------------------------------------------------------------
Shape the Mobile Experience: Free Subscription
Software experts and developers: Be at the forefront of tech innovation.
Intel(R) Software Adrenaline delivers strategic insight and game-changing 
conversations that shape the rapidly evolving mobile landscape. Sign up now. 
http://pubads.g.doubleclick.net/gampad/clk?id=63431311&iu=/4140/ostg.clktrk
_______________________________________________
Scikit-learn-general mailing list
Scikit-learn-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general

Reply via email to