49. NumPy Datatypes in Python with Code || Random Function NumPy Arrays Python Programming Tutorial

Опубликовано: 10 Октябрь 2024
на канале: Bhavatavi
5
0

NumPy uses much less memory to store data and it provides a mechanism of specifying the data types. A NumPy array can store different data String, Integer, Complex, Float, Boolean.
NumPy offers the random module to work with random numbers. The numpy.random.randn() function creates an array of specified shape and fills it with random values.

Numpy part I Link:    • 48. NumPy Array in Python with Code  ...  
Numpy part III Link:    • 50. NumPy Array Indexing in Python wi...  
Numpy part IV Link:    • 51. NumPy Array Math in Python with C...  
Numpy part V Link:    • 52. NumPy Arrays Reorganizing Functio...  

Code:
import numpy as np
x=np.array([1,2])
print(x.dtype)

xf=np.array([1.4,2.0])
print(xf.dtype)

x64=np.array([1,2],dtype=np.int64)
print(x64.dtype)


y=np.random.randn(4,3)
print(y)

yrandint=np.random.randint(2,100)
print(yrandint)

y=np.random.randint(-4,8,size=(3,3))
print(y)

print(x,y)