Skip to content

Instantly share code, notes, and snippets.

@godber
Last active August 29, 2015 14:26
Show Gist options
  • Save godber/5ba8f5c38004ae023706 to your computer and use it in GitHub Desktop.
Save godber/5ba8f5c38004ae023706 to your computer and use it in GitHub Desktop.
Creating an ndarray with a given dtype.
import numpy as np
dt = np.dtype([
('time', [('min', int), ('sec', int)]),
('temp', float)
])
# create array with dtype
x = np.zeros((5,5), dtype=dt)
# Initialize values
x['time']['min'] = 10
x['temp'] = 98.25
# show array
x
# show temps
x['temp']
@godber
Copy link
Author

godber commented Aug 6, 2015

This example comes from http://docs.scipy.org/doc/numpy/reference/generated/numpy.fromfile.html except I create a 5 by 5 array.

@godber
Copy link
Author

godber commented Aug 6, 2015

Examples of more complex dtypes can be found here:

http://docs.scipy.org/doc/numpy/reference/generated/numpy.dtype.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment