I have the following code. I have a matrix that I want to take two rows at a time and put into these functions. I've looked through intertools, but I wasn't sure if they would work in this instance. I tried islice, but it didn't give the output I wanted. I know that I have to give the 'methods' the positional arguments, but I've left them out because this code will give results, they are just the same min,max and such over and over. What I was trying was giving me issues about index errors, and objects not being subscriptable. I'm new to python, and I'm working through some books, but they do not cover this directly. I've looked over what some people are looking for on stackoverflow, but they mostly want to read in files 2 rows at a time, not numpy ndarrays. Any suggestions are appreciated.
import numpy as np
def xmax():
for i in range(1):
setOne = (matrix[i:1])
setTwo = (matrix[i+1:2])
if setOne[i][0:1] > setTwo[i][0:1]:
xMax = setOne[i][0:1]
else:
xMax = setTwo[i][0:1]
return(xMax)
def xmin():
for i in range(1):
setOne = (matrix[i:1])
setTwo = (matrix[i+1:2])
if setOne[i][0:1] < setTwo[i][0:1]:
xMin = setOne[i][0:1]
else:
xMin = setTwo[i][0:1]
return(xMin)
def ymax():
for i in range(1):
setOne = (matrix[i:1])
setTwo = (matrix[i+1:2])
if setOne[i][1:2] > setTwo[i][1:2]:
yMax = setOne[i][1:2]
else:
yMax = setTwo[i][1:2]
return(yMax)
def ymin():
for i in range(1):
setOne = (matrix[i:1])
setTwo = (matrix[i+1:2])
if setOne[i][1:2] < setTwo[i][1:2]:
yMin = setOne[i][1:2]
else:
yMin = setTwo[i][1:2]
return(yMin)
def zmax():
for i in range(1):
setOne = (matrix[i:1])
setTwo = (matrix[i+2:3])
if setOne[i][2:3] > setTwo[i][2:3]:
zMax = setOne[i][2:3]
else:
zMax = setTwo[i][2:3]
return(zMax)
def zmin():
for i in range(1):
setOne = (matrix[i:1])
setTwo = (matrix[i+2:3])
if setOne[i][2:3] < setTwo[i][2:3]:
zMin = setOne[i][2:3]
else:
zMin = setTwo[i][2:3]
return(zMin)
'''***********************************************************************************
Created on Jan 27, 2013
@author:
***********************************************************************************'''
f ='/Users/Documents/workspace/findMinMax/crapc.txt'
x,y,z = np.loadtxt(f, unpack=True, usecols=(1,2,3), ndmin = 2)
maxZ = max(z)
minZ = min(z)
print("Maximum Z value: " + str(maxZ))
print("Minimum Z value: " + str(minZ))
matrix = [x,y,z]
matrix = np.rot90(matrix)
matrix = matrix[::-1]
"""for each_row in range(0,len(matrix)-1,2):
print("Xmax:" + str(xmax()))
print("Xmin:" + str(xmin()))
print("Ymax:" + str(ymax()))
print("Ymin:" + str(ymin()))
print("Zmax:" + str(zmax()))
print("Zmin:" + str(zmin()))"""
range(1)for --- they only contain a single value, zero.minandmaxfunctions, i.e.numpy.max(z)or evenz.max(). The documentation shows how you can take the maximum of each column or row (using theaxiskeyword).