File tree Expand file tree Collapse file tree 1 file changed +32
-1
lines changed Expand file tree Collapse file tree 1 file changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -216,4 +216,35 @@ The `timedelta64()` used to find the difference between the `datetime64()`. The
216
216
# 366 days
217
217
# timedelta64[D]
218
218
```
219
- # Data Type Conversion
219
+ # Data Type Conversion
220
+ ` astype() ` function is used to the NumPy object from one type to another type.
221
+
222
+ It creates a copy of the array and allows to specify the data type of our choice.
223
+
224
+ ## Example 1
225
+
226
+ ``` python
227
+ import numpy as np
228
+
229
+ x = np.array([1.2 , 3.4 , 5.6 ])
230
+ y = x.astype(int )
231
+
232
+ print (y,y.dtype)
233
+
234
+ # Output:
235
+ # [1 3 5] int64
236
+ ```
237
+
238
+ ## Example 2
239
+
240
+ ``` python
241
+ import numpy as np
242
+
243
+ x = np.array([1 , 3 , 0 ])
244
+ y = x.astype(bool )
245
+
246
+ print (y,y.dtype)
247
+
248
+ # Output:
249
+ # [True True False] bool
250
+ ```
You can’t perform that action at this time.
0 commit comments