From c4b980f9d983d2888528226434daff715857efec Mon Sep 17 00:00:00 2001 From: yhirose Date: Tue, 12 Sep 2023 16:56:17 -0400 Subject: [PATCH] Use buit-in type `int` instead of deprecated `np.int` Reference from numpy: AttributeError: module 'numpy' has no attribute 'int'. `np.int` was a deprecated alias for the builtin `int`. To avoid this error in existing code, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information. The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at: --- dezero/datasets.py | 4 ++-- dezero/transforms.py | 2 +- examples/gan.py | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dezero/datasets.py b/dezero/datasets.py index c43ce83..86ec727 100644 --- a/dezero/datasets.py +++ b/dezero/datasets.py @@ -47,7 +47,7 @@ def get_spiral(train=True): num_data, num_class, input_dim = 100, 3, 2 data_size = num_class * num_data x = np.zeros((data_size, input_dim), dtype=np.float32) - t = np.zeros(data_size, dtype=np.int) + t = np.zeros(data_size, dtype=int) for j in range(num_class): for i in range(num_data): @@ -137,7 +137,7 @@ def prepare(self): filepath = get_file(url) if self.train: self.data = np.empty((50000, 3 * 32 * 32)) - self.label = np.empty((50000), dtype=np.int) + self.label = np.empty((50000), dtype=int) for i in range(5): self.data[i * 10000:(i + 1) * 10000] = self._load_data( filepath, i + 1, 'train') diff --git a/dezero/transforms.py b/dezero/transforms.py index 8bcf1b0..df01b17 100644 --- a/dezero/transforms.py +++ b/dezero/transforms.py @@ -151,5 +151,5 @@ def __call__(self, array): class ToInt(AsType): - def __init__(self, dtype=np.int): + def __init__(self, dtype=int): self.dtype = dtype diff --git a/examples/gan.py b/examples/gan.py index 7784554..9d314ce 100755 --- a/examples/gan.py +++ b/examples/gan.py @@ -74,8 +74,8 @@ def init_weight(dis, gen, hidden_size): else: xp = np -label_real = xp.ones(batch_size).astype(np.int) -label_fake = xp.zeros(batch_size).astype(np.int) +label_real = xp.ones(batch_size).astype(int) +label_fake = xp.zeros(batch_size).astype(int) test_z = xp.random.randn(25, hidden_size).astype(np.float32) @@ -130,4 +130,4 @@ def generate_image(): epoch_detail = epoch + cnt / train_loader.max_iter print('epoch: {:.2f}, loss_g: {:.4f}, loss_d: {:.4f}'.format( epoch_detail, float(avg_loss_g/cnt), float(avg_loss_d/cnt))) - generate_image() \ No newline at end of file + generate_image()