Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

numpy datatypes

import numpy as np

arr = np.array([1, 2, 3, 4])

# print array datatype
print(arr.dtype)
# output int64

# 8 byte integer datatype
arr = np.array([1, 2, 3, 4], dtype="i8")
print(arr)
# output [1 2 3 4]

# string datatype
arr = np.array([1, 2, 3, 4], dtype="S")
print(arr)
# output [b'1' b'2' b'3' b'4']

arr = np.array([1, 0, 3])

# converting arrays
arr = arr.astype(str)
print(arr)
# output ['1' '0' '3']

arr = arr.astype(float)
print(arr)
# output [1. 0. 3.]

arr = arr.astype(bool)
print(arr)
# output [ True False  True]

print(arr.dtype)
# output bool

arr = np.array(["mike", "sam"])
arr = arr.astype(int)
# output ValueError: invalid literal for int() with base 10: 'mike'

# data types

# i - integer
# b - boolean
# u - unsigned integer
# f - float
# c - complex float
# m - timedelta
# M - datetime
# O - object
# S - string
# U - unicode string
# V - fixed chunk of memory for other type ( void )
Comment

data types in numpy array

import numpy as np
>>> x = np.float32(1.0)
>>> x
1.0
>>> y = np.int_([1,2,4])
>>> y
array([1, 2, 4])
>>> z = np.arange(3, dtype=np.uint8)
>>> z
array([0, 1, 2], dtype=uint8)
Comment

PREVIOUS NEXT
Code Example
Python :: graph implementation in python 
Python :: pip in python 
Python :: python dlib 
Python :: lru_cache 
Python :: python format new 
Python :: torch.nan_to_num 
Python :: django 3 create async rest api 
Python :: pydrive download by url 
Python :: how to append a tuple to a list 
Python :: gfg placement course 
Python :: pythagoras theorem formula 
Python :: how to open annaconda 
Python :: python collections to dictionary 
Python :: if condition in python lambda 
Python :: python invert colormap 
Python :: python any in string 
Python :: parse xml in python 
Python :: pandas multiply all dataframe 
Python :: python remove first item in list 
Python :: download video to from pytube with a special name 
Python :: check if a word is a noun python 
Python :: Python Iterating Through an Iterator 
Python :: python list remove duplicates keep order 
Python :: time zone in python 
Python :: remove all consecutive duplicates from the string 
Python :: how to perform group by with django orm 
Python :: remove figure label 
Python :: production mode flask 
Python :: How To Display An Image On A Tkinter Button 
Python :: hmac sha256 python 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =