From: Stefan v. d. W. <st...@su...> - 2006-07-06 07:21:29
|
On Thu, Jul 06, 2006 at 11:39:19AM +0900, Bill Baxter wrote: > Often when I'm doing interactive prototyping I find myself wanting to c= heck > whether two arrays are sharing a copy of the same data. >=20 > It seems like there ought to be a concise way to do that, but right now= seems > like the only way is with a little function like this: >=20 > def same_base(a,b): > ab =3D a.base > if ab is None: ab =3D a > bb =3D b.base > if bb is None: bb =3D b > return ab is bb =20 >=20 > is there some easier built-in way? Does the above function even cover = all the > bases? (so to speak...) Say you have x =3D N.array([1,2,3,4]) and y =3D x.reshape((2,2)) then x and y share the same data. You can see this when you do x.__array_interface__['data'][0] =3D=3D y.__array_interface__['data'][0] Still, this only holds for full data views. If you had z =3D y[1:,1:] then the data memory position would differ. Cheers St=E9fan |