Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9e67895

Browse files
committed
MAINT: get rid of np.int
np.int is a confusing synonym for __builtin__.int; it maps to C long, the size of which is platform-dependent. The NumPy devs are speaking of deprecating np.int, and all uses of it in SciPy have been replaced. See http://github.com/numpy/numpy#6103 for rationale.
1 parent b52054f commit 9e67895

17 files changed

+26
-26
lines changed

benchmarks/bench_covertype.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def load_data(dtype=np.float32, order='C', random_state=13):
7777
data = fetch_covtype(download_if_missing=True, shuffle=True,
7878
random_state=random_state)
7979
X = check_array(data['data'], dtype=dtype, order=order)
80-
y = (data['target'] != 1).astype(np.int)
80+
y = (data['target'] != 1).astype(int)
8181

8282
## Create train-test split (as [Joachims, 2006])
8383
print("Creating train-test split...")

benchmarks/bench_lasso.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def compute_bench(alpha, n_samples, n_features, precompute):
6464
alpha = 0.01 # regularization parameter
6565

6666
n_features = 10
67-
list_n_samples = np.linspace(100, 1000000, 5).astype(np.int)
67+
list_n_samples = np.linspace(100, 1000000, 5).astype(int)
6868
lasso_results, lars_lasso_results = compute_bench(alpha, list_n_samples,
6969
[n_features], precompute=True)
7070

@@ -81,7 +81,7 @@ def compute_bench(alpha, n_samples, n_features, precompute):
8181
pl.axis('tight')
8282

8383
n_samples = 2000
84-
list_n_features = np.linspace(500, 3000, 5).astype(np.int)
84+
list_n_features = np.linspace(500, 3000, 5).astype(int)
8585
lasso_results, lars_lasso_results = compute_bench(alpha, [n_samples],
8686
list_n_features, precompute=False)
8787
pl.subplot(212)

benchmarks/bench_plot_fastkmeans.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ def compute_bench_2(chunks):
9595
from mpl_toolkits.mplot3d import axes3d # register the 3d projection
9696
import matplotlib.pyplot as plt
9797

98-
samples_range = np.linspace(50, 150, 5).astype(np.int)
99-
features_range = np.linspace(150, 50000, 5).astype(np.int)
100-
chunks = np.linspace(500, 10000, 15).astype(np.int)
98+
samples_range = np.linspace(50, 150, 5).astype(int)
99+
features_range = np.linspace(150, 50000, 5).astype(int)
100+
chunks = np.linspace(500, 10000, 15).astype(int)
101101

102102
results = compute_bench(samples_range, features_range)
103103
results_2 = compute_bench_2(chunks)

benchmarks/bench_plot_nmf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ def benchmark(samples_range, features_range, rank=50, tolerance=1e-5):
146146
axes3d
147147
import matplotlib.pyplot as plt
148148

149-
samples_range = np.linspace(50, 500, 3).astype(np.int)
150-
features_range = np.linspace(50, 500, 3).astype(np.int)
149+
samples_range = np.linspace(50, 500, 3).astype(int)
150+
features_range = np.linspace(50, 500, 3).astype(int)
151151
timeset, err = benchmark(samples_range, features_range)
152152

153153
for i, results in enumerate((timeset, err)):

benchmarks/bench_plot_omp_lars.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ def compute_bench(samples_range, features_range):
100100

101101

102102
if __name__ == '__main__':
103-
samples_range = np.linspace(1000, 5000, 5).astype(np.int)
104-
features_range = np.linspace(1000, 5000, 5).astype(np.int)
103+
samples_range = np.linspace(1000, 5000, 5).astype(int)
104+
features_range = np.linspace(1000, 5000, 5).astype(int)
105105
results = compute_bench(samples_range, features_range)
106106
max_time = max(np.max(t) for t in results.values())
107107

benchmarks/bench_plot_svd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ def compute_bench(samples_range, features_range, n_iter=3, rank=50):
5757
from mpl_toolkits.mplot3d import axes3d # register the 3d projection
5858
import matplotlib.pyplot as plt
5959

60-
samples_range = np.linspace(2, 1000, 4).astype(np.int)
61-
features_range = np.linspace(2, 1000, 4).astype(np.int)
60+
samples_range = np.linspace(2, 1000, 4).astype(int)
61+
features_range = np.linspace(2, 1000, 4).astype(int)
6262
results = compute_bench(samples_range, features_range)
6363

6464
label = 'scikit-learn singular value decomposition benchmark results'

benchmarks/bench_plot_ward.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
pl.imshow(np.log(ratio), aspect='auto', origin="lower")
3636
pl.colorbar()
3737
pl.contour(ratio, levels=[1, ], colors='k')
38-
pl.yticks(range(len(n_features)), n_features.astype(np.int))
38+
pl.yticks(range(len(n_features)), n_features.astype(int))
3939
pl.ylabel('N features')
40-
pl.xticks(range(len(n_samples)), n_samples.astype(np.int))
40+
pl.xticks(range(len(n_samples)), n_samples.astype(int))
4141
pl.xlabel('N samples')
4242
pl.title("Scikit's time, in units of scipy time (log)")
4343
pl.show()

benchmarks/bench_sample_without_replacement.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def bench_sample(sampling, n_population, n_samples):
145145
###########################################################################
146146
time = {}
147147
n_samples = np.linspace(start=0, stop=opts.n_population,
148-
num=opts.n_steps).astype(np.int)
148+
num=opts.n_steps).astype(int)
149149

150150
ratio = n_samples / opts.n_population
151151

benchmarks/bench_sgd_regression.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from sklearn.datasets.samples_generator import make_regression
2323

2424
if __name__ == "__main__":
25-
list_n_samples = np.linspace(100, 10000, 5).astype(np.int)
25+
list_n_samples = np.linspace(100, 10000, 5).astype(int)
2626
list_n_features = [10, 100, 1000]
2727
n_test = 1000
2828
noise = 0.1

examples/applications/plot_tomography_l1_reconstruction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def generate_synthetic_data():
104104
mask_outer = (x - l / 2) ** 2 + (y - l / 2) ** 2 < (l / 2) ** 2
105105
mask = np.zeros((l, l))
106106
points = l * rs.rand(2, n_pts)
107-
mask[(points[0]).astype(np.int), (points[1]).astype(np.int)] = 1
107+
mask[(points[0]).astype(int), (points[1]).astype(int)] = 1
108108
mask = ndimage.gaussian_filter(mask, sigma=l / n_pts)
109109
res = np.logical_and(mask > mask.mean(), mask_outer)
110110
return res - ndimage.binary_erosion(res)

examples/cluster/plot_adjusted_for_chance_measures.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def uniform_labelings_scores(score_func, n_samples, n_clusters_range,
6666
# 2 independent random clusterings with equal cluster number
6767

6868
n_samples = 100
69-
n_clusters_range = np.linspace(2, n_samples, 10).astype(np.int)
69+
n_clusters_range = np.linspace(2, n_samples, 10).astype(int)
7070

7171
plt.figure(1)
7272

@@ -95,7 +95,7 @@ def uniform_labelings_scores(score_func, n_samples, n_clusters_range,
9595
# with fixed number of clusters
9696

9797
n_samples = 1000
98-
n_clusters_range = np.linspace(2, 100, 10).astype(np.int)
98+
n_clusters_range = np.linspace(2, 100, 10).astype(int)
9999
n_classes = 10
100100

101101
plt.figure(2)

examples/cluster/plot_cluster_comparison.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
algorithm.fit(X)
9898
t1 = time.time()
9999
if hasattr(algorithm, 'labels_'):
100-
y_pred = algorithm.labels_.astype(np.int)
100+
y_pred = algorithm.labels_.astype(int)
101101
else:
102102
y_pred = algorithm.predict(X)
103103

examples/linear_model/plot_logistic_l1_l2_sparsity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
X = StandardScaler().fit_transform(X)
3434

3535
# classify small against large digits
36-
y = (y > 4).astype(np.int)
36+
y = (y > 4).astype(int)
3737

3838

3939
# Set regularization parameter

sklearn/cluster/hierarchical.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ def linkage_tree(X, connectivity=None, n_components=None,
428428
i, j = np.triu_indices(X.shape[0], k=1)
429429
X = X[i, j]
430430
out = hierarchy.linkage(X, method=linkage, metric=affinity)
431-
children_ = out[:, :2].astype(np.int)
431+
children_ = out[:, :2].astype(int)
432432

433433
if return_distance:
434434
distances = out[:, 2]

sklearn/cluster/k_means_.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ def _labels_inertia_precompute_dense(X, x_squared_norms, centers, distances):
469469
470470
Returns
471471
-------
472-
labels : numpy array, dtype=np.int, shape (n_samples,)
472+
labels : numpy array, dtype=np.int32, shape (n_samples,)
473473
Indices of clusters that samples are assigned to.
474474
475475
inertia : float
@@ -523,7 +523,7 @@ def _labels_inertia(X, x_squared_norms, centers,
523523
524524
Returns
525525
-------
526-
labels: int array of shape(n)
526+
labels: int32 array of shape(n)
527527
The resulting assignment
528528
529529
inertia : float

sklearn/cluster/mean_shift_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def mean_shift(X, bandwidth=None, seeds=None, bin_seeding=False,
193193

194194
# ASSIGN LABELS: a point belongs to the cluster that it is closest to
195195
nbrs = NearestNeighbors(n_neighbors=1).fit(cluster_centers)
196-
labels = np.zeros(n_samples, dtype=np.int)
196+
labels = np.zeros(n_samples, dtype=int)
197197
distances, idxs = nbrs.kneighbors(X)
198198
if cluster_all:
199199
labels = idxs.flatten()

sklearn/cluster/tests/test_hierarchical.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def test_scikit_vs_scipy():
251251

252252
out = hierarchy.linkage(X, method=linkage)
253253

254-
children_ = out[:, :2].astype(np.int)
254+
children_ = out[:, :2].astype(int)
255255
children, _, n_leaves, _ = _TREE_BUILDERS[linkage](X, connectivity)
256256

257257
cut = _hc_cut(k, children, n_leaves)

0 commit comments

Comments
 (0)