[Numpy-discussion] How are non-contiguous arrays created?

Chris Barker Chris.Barker at noaa.gov
Thu Jun 27 15:07:04 EDT 2002


Norman Davis wrote:
> How is a
> non-contiguous array created?

By slicing an array. Since slicing created a "view" into the same data,
it may not represent a contiguous portion of memory. Example:

>>> from Numeric import *
>>> a = ones((3,4))
>>> a
array([[1, 1, 1, 1],
       [1, 1, 1, 1],
       [1, 1, 1, 1]])
>>> a.iscontiguous()
1
# a newly created array will always be contiguous

>>> b = a[3:3,:]
>>> b.iscontiguous()
1
# sliced this way, you get a contiguous array
>>> c = a[:,3:3]
>>> c.iscontiguous()
0
#but sliced another way you don't

-Chris


-- 
Christopher Barker, Ph.D.
Oceanographer
                                    		
NOAA/OR&R/HAZMAT         (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov




More information about the NumPy-Discussion mailing list