Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Column xyz data to grid for plotting
- x y z
- 1 1 10
- 1 2 12
- 2 1 14
- 2 2 16
- 10 12
- 14 16
- import numpy
- idx1 = numpy.array([0, 0, 1, 1])
- idx2 = numpy.array([0, 1, 0, 1])
- data = numpy.array([10, 12, 14, 16])
- grid = numpy.zeros(len(data)/2, 2)
- grid[idx1, idx2] = data
- >>>grid
- array([[ 10., 12.],
- [ 14., 16.]])
- data.txt
- x y z
- 1 1 10
- 1 2 12
- 2 1 14
- 2 2 16
- def extract(filepath):
- f = open(filepath)
- f.readline() # to read out the first line that says "x y z"
- while 1:
- x = f.readline().strip().split()[-1]
- y = f.readline().strip().split()[-1]
- print x, y
- data.txt
- x y z
- 1 1 10
- 2 1 14
- 1 2 12
- 2 2 16
- from collections import defaultdict
- def extract(filepath):
- coords = defaultdict(dict)
- f = open(filepath)
- f.readline() # to read out the first line that says "x y z"
- for line in f:
- id, axis, val = map(int, line.strip().split())
- coords[id][axis] = val
- for i in sorted(coords):
- print coords[i][1], coords[i][2]
Advertisement
Add Comment
Please, Sign In to add comment