Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit912bb80

Browse files
committed
Use ndim, size whereever appropriate.
1 parent58b6dc6 commit912bb80

File tree

9 files changed

+19
-33
lines changed

9 files changed

+19
-33
lines changed

‎examples/statistics/errorbar_limits.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
# Plot a series with lower and upper limits in both x & y
5353
# constant x-error with varying y-error
5454
xerr=0.2
55-
yerr=np.zeros(x.shape)+0.2
55+
yerr=np.zeros_like(x)+0.2
5656
yerr[[3,6]]=0.3
5757

5858
# mock up some limits by modifying previous data

‎lib/matplotlib/axes/_axes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5214,10 +5214,10 @@ def _pcolorargs(funcname, *args, **kw):
52145214

52155215
Nx=X.shape[-1]
52165216
Ny=Y.shape[0]
5217-
iflen(X.shape)!=2orX.shape[0]==1:
5217+
ifX.ndim!=2orX.shape[0]==1:
52185218
x=X.reshape(1,Nx)
52195219
X=x.repeat(Ny,axis=0)
5220-
iflen(Y.shape)!=2orY.shape[1]==1:
5220+
ifY.ndim!=2orY.shape[1]==1:
52215221
y=Y.reshape(Ny,1)
52225222
Y=y.repeat(Nx,axis=1)
52235223
ifX.shape!=Y.shape:

‎lib/matplotlib/image.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,8 +848,7 @@ def set_data(self, x, y, A):
848848
x=np.array(x,np.float32)
849849
y=np.array(y,np.float32)
850850
A=cbook.safe_masked_invalid(A,copy=True)
851-
iflen(x.shape)!=1orlen(y.shape)!=1\
852-
orA.shape[0:2]!= (y.shape[0],x.shape[0]):
851+
ifnot (x.ndim==y.ndim==1andA.shape[0:2]==y.shape+x.shape):
853852
raiseTypeError("Axes don't match array shape")
854853
ifA.ndimnotin [2,3]:
855854
raiseTypeError("Can only plot 2D or 3D data")

‎lib/matplotlib/mlab.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ def _single_spectrum_helper(x, mode, Fs=None, window=None, pad_to=None,
802802
ifmode!='complex':
803803
spec=spec.real
804804

805-
iflen(spec.shape)==2andspec.shape[1]==1:
805+
ifspec.ndim==2andspec.shape[1]==1:
806806
spec=spec[:,0]
807807

808808
returnspec,freqs
@@ -1013,7 +1013,7 @@ def csd(x, y, NFFT=None, Fs=None, detrend=None, window=None,
10131013
sides=sides,scale_by_freq=scale_by_freq,
10141014
mode='psd')
10151015

1016-
iflen(Pxy.shape)==2:
1016+
ifPxy.ndim==2:
10171017
ifPxy.shape[1]>1:
10181018
Pxy=Pxy.mean(axis=1)
10191019
else:
@@ -1673,16 +1673,12 @@ def project(self, x, minfrac=0.):
16731673
of variance<minfrac
16741674
'''
16751675
x=np.asarray(x)
1676-
1677-
ndims=len(x.shape)
1678-
1679-
if (x.shape[-1]!=self.numcols):
1676+
ifx.shape[-1]!=self.numcols:
16801677
raiseValueError('Expected an array with dims[-1]==%d'%
16811678
self.numcols)
1682-
16831679
Y=np.dot(self.Wt,self.center(x).T).T
16841680
mask=self.fracs>=minfrac
1685-
ifndims==2:
1681+
ifx.ndim==2:
16861682
Yreduced=Y[:,mask]
16871683
else:
16881684
Yreduced=Y[mask]

‎lib/matplotlib/testing/compare.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def calculate_rms(expectedImage, actualImage):
254254
raiseImageComparisonFailure(
255255
"image sizes do not match expected size: {0} "
256256
"actual size {1}".format(expectedImage.shape,actualImage.shape))
257-
num_values=np.prod(expectedImage.shape)
257+
num_values=expectedImage.size
258258
abs_diff_image=abs(expectedImage-actualImage)
259259
histogram=np.bincount(abs_diff_image.ravel(),minlength=256)
260260
sum_of_squares=np.sum(histogram*np.arange(len(histogram))**2)

‎lib/matplotlib/tests/test_axes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2359,13 +2359,13 @@ def test_errorbar_limits():
23592359
plt.errorbar(x,y,xerr=xerr,yerr=yerr,ls=ls,color='blue')
23602360

23612361
# including upper limits
2362-
uplims=np.zeros(x.shape)
2362+
uplims=np.zeros_like(x)
23632363
uplims[[1,5,9]]=True
23642364
plt.errorbar(x,y+0.5,xerr=xerr,yerr=yerr,uplims=uplims,ls=ls,
23652365
color='green')
23662366

23672367
# including lower limits
2368-
lolims=np.zeros(x.shape)
2368+
lolims=np.zeros_like(x)
23692369
lolims[[2,4,8]]=True
23702370
plt.errorbar(x,y+1.0,xerr=xerr,yerr=yerr,lolims=lolims,ls=ls,
23712371
color='red')
@@ -2376,12 +2376,12 @@ def test_errorbar_limits():
23762376

23772377
# including xlower and xupper limits
23782378
xerr=0.2
2379-
yerr=np.zeros(x.shape)+0.2
2379+
yerr=np.zeros_like(x)+0.2
23802380
yerr[[3,6]]=0.3
23812381
xlolims=lolims
23822382
xuplims=uplims
2383-
lolims=np.zeros(x.shape)
2384-
uplims=np.zeros(x.shape)
2383+
lolims=np.zeros_like(x)
2384+
uplims=np.zeros_like(x)
23852385
lolims[[6]]=True
23862386
uplims[[3]]=True
23872387
plt.errorbar(x,y+2.1,marker='o',ms=8,xerr=xerr,yerr=yerr,

‎lib/matplotlib/tri/triangulation.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Triangulation(object):
4141
def__init__(self,x,y,triangles=None,mask=None):
4242
self.x=np.asarray(x,dtype=np.float64)
4343
self.y=np.asarray(y,dtype=np.float64)
44-
ifself.x.shape!=self.y.shapeorlen(self.x.shape)!=1:
44+
ifself.x.shape!=self.y.shapeorx.ndim!=1:
4545
raiseValueError("x and y must be equal-length 1-D arrays")
4646

4747
self.mask=None
@@ -67,8 +67,7 @@ def __init__(self, x, y, triangles=None, mask=None):
6767

6868
ifmaskisnotNone:
6969
self.mask=np.asarray(mask,dtype=np.bool)
70-
if (len(self.mask.shape)!=1or
71-
self.mask.shape[0]!=self.triangles.shape[0]):
70+
ifself.mask.shape!= (self.triangles.shape[0],):
7271
raiseValueError('mask array must have same length as '
7372
'triangles array')
7473

@@ -202,8 +201,7 @@ def set_mask(self, mask):
202201
self.mask=None
203202
else:
204203
self.mask=np.asarray(mask,dtype=np.bool)
205-
if (len(self.mask.shape)!=1or
206-
self.mask.shape[0]!=self.triangles.shape[0]):
204+
ifself.mask.shape!= (self.triangles.shape[0],):
207205
raiseValueError('mask array must have same length as '
208206
'triangles array')
209207

‎lib/matplotlib/tri/triinterpolate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def _interpolate_multikeys(self, x, y, tri_index=None,
166166
x=np.asarray(x,dtype=np.float64)
167167
y=np.asarray(y,dtype=np.float64)
168168
sh_ret=x.shape
169-
if(x.shape!=y.shape):
169+
ifx.shape!=y.shape:
170170
raiseValueError("x and y shall have same shapes."
171171
" Given: {0} and {1}".format(x.shape,y.shape))
172172
x=np.ravel(x)

‎lib/mpl_toolkits/mplot3d/proj3d.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,7 @@ def inv_transform(xs, ys, zs, M):
152152
returnvecr[0],vecr[1],vecr[2]
153153

154154
defvec_pad_ones(xs,ys,zs):
155-
try:
156-
try:
157-
vec=np.array([xs,ys,zs,np.ones(xs.shape)])
158-
except (AttributeError,TypeError):
159-
vec=np.array([xs,ys,zs,np.ones((len(xs)))])
160-
exceptTypeError:
161-
vec=np.array([xs,ys,zs,1])
162-
returnvec
155+
returnnp.array([xs,ys,zs,np.ones_like(xs)])
163156

164157
defproj_transform(xs,ys,zs,M):
165158
"""

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp