Last active
August 29, 2015 14:26
-
-
Save godber/5ba8f5c38004ae023706 to your computer and use it in GitHub Desktop.
Creating an ndarray with a given dtype.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] |
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
This example comes from http://docs.scipy.org/doc/numpy/reference/generated/numpy.fromfile.html except I create a 5 by 5 array.