예제 #1
0
 def ReadDiskData(self, filename):
   if self.verbose:
     print 'Reading from disk %s' % filename
   ext = os.path.splitext(filename)[1]
   if ext == '.npy':
     data = np.load(filename)
   elif ext == '.mat':
     if 'key' in kwargs.keys():
         key = kwargs['key']
     else:
         key = desc
     data = scipy.io.loadmat(filename, struct_as_record = True)[key]
   elif ext == '.p':
     data = pickle.load(gzip.GzipFile(filename, 'rb'))
   elif ext == '.txt':
     data = np.loadtext(filename)
   elif ext == '.npz':
     data = self.load_sparse(filename)
   else:
     raise Exception('Unknown file extension %s' % ext)
   if data.dtype == 'float64':
     data = data.astype('float32')
   if self.subtract_mean:
     data -= self.mean
   if self.divide_stddev:
     data /= self.stddev
   if len(data.shape) == 1 or (len(data.shape)==2 and (
     data.shape[0] == 1 or data.shape[1] == 1)):
     data = data.reshape(-1, 1)
   return data
예제 #2
0
  def ReadDiskData(self, filename, key=''):
    """Reads data from filename."""
    if self.verbose:
      print 'Reading from disk %s' % filename
    ext = os.path.splitext(filename)[1]
    if ext == '.npy':
      data = np.load(filename)
    elif ext == '.mat':
      data = scipy.io.loadmat(filename, struct_as_record = True)[key]
    elif ext == '.p':
      data = pickle.load(gzip.GzipFile(filename, 'rb'))
    elif ext == '.txt':
      data = np.loadtext(filename)
    elif ext == '.npz':
      data = Disk.LoadSparse(filename, verbose=self.verbose)
    elif ext == '.spec':
      data = Disk.LoadPickle(filename, key, verbose=self.verbose)
    else:
      raise Exception('Unknown file extension %s' % ext)
    if data.dtype == 'float64':
      data = data.astype('float32')

    # 1-D data as column vector.
    if len(data.shape) == 1 or (len(data.shape)==2 and data.shape[0] == 1):
      data = data.reshape(-1, 1)

    return data
예제 #3
0
    def ReadDiskData(self, filename, key=''):
        """Reads data from filename."""
        if self.verbose:
            print 'Reading from disk %s' % filename
        ext = os.path.splitext(filename)[1]
        if ext == '.npy':
            data = np.load(filename)
        elif ext == '.mat':
            data = scipy.io.loadmat(filename, struct_as_record=True)[key]
        elif ext == '.p':
            data = pickle.load(gzip.GzipFile(filename, 'rb'))
        elif ext == '.txt':
            data = np.loadtext(filename)
        elif ext == '.npz':
            data = Disk.LoadSparse(filename, verbose=self.verbose)
        elif ext == '.spec':
            data = Disk.LoadPickle(filename, key, verbose=self.verbose)
        else:
            raise Exception('Unknown file extension %s' % ext)
        if data.dtype == 'float64':
            data = data.astype('float32')

        # 1-D data as column vector.
        if len(data.shape) == 1 or (len(data.shape) == 2
                                    and data.shape[0] == 1):
            data = data.reshape(-1, 1)

        return data
예제 #4
0
def read_feature_from_file(filename):
    '''
    读取特征值属性,然后将其以矩阵形式返回
    '''

    f = np.loadtext(filename)
    #返回特征位置、描述子
    return f[:, :4], f[:, 4:]
예제 #5
0
def graphData(stock):
    try:
        stockFile = stock+'.txt'

	date, closep,highp,lowp,openp,volume = np.loadtext(stockFile,delimeter=',',unpack=True,converters ={ 0: mdates.strpdate2num('%Y%m%d')})
        fig = plt.figure()
	ax1 = plot.subplot(1,1,1)#(2,3,1) would be position 1 in a 2 by 3 square
	ax1.plot(date, openp)
	ax1.plot(date, highp)
	ax1.plot(date, lowp)
	ax1.plot(date, closep)
	
	ax1.xaxis.set_major+locator(mticker.MaxNLocator(10)) #max of 10 dates
        ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
	for label in ax1.xaxis.get_ticklables():
	    label.set_rotation(45)

	plt.show()
    except Exception,e:
        print 'failed main loop',str(e)
예제 #6
0
    def prepare(self, resfile=None):
        """prepare system to scan for eta parameters by reading in resonance
            locations
           
           Args:
            resfile (str): optional path resonance locations
            If none supplied, then most recent _resloc file is used

           Outputs:
            freqs (list): list of frequency locations
        """
        if resfile is not None:
            reslocs = resfile
        else:
            resfiles = sorted([f for f in os.listdir(self.outputdir) if
            "res_locs" in f]) # move nickname to a variable?
            reslocs = resfiles[-1] # grab the most recent

        data = np.loadtext(reslocs, dtype=float, delimiter=',', skiprows=1)
        freqs = data[:,0] # assumes frequencies are in the first column
        self.freqs = freqs
        return freqs
예제 #7
0
파일: use_qe.py 프로젝트: jinga-lala/CS-251
from qe import quaternion_to_euler as qte 
from qe import euler_to_quaternion as etq 
import sys
import numpy as np 

if __name__=="__main__":
	if(len(sys.argv)<3):
		print("Enter infile,outfile and choice")
		exit(1)
	infile_n=sys.argv[1]
	outfile_n=sys.argv[2]
	choice=sys.argv[3]
	infile=open(infile_n,"r")
	outfile=open(outfile_n,"w")
	i=np.loadtext(infile,delimiter=",")
	if(choice=='0'):
		if(i.shape[1]==4):
			euler=qte(i)
			np.writetext(outfile,delimiter=",")
		else:
			print("Wrong dimensions")
			exit(1)
	else:
		if(i.shape[1]==3):
			quaternion=etq(i)
			np.writetext(outfile,delimiter=",")
		else:
			print("Wrong dimensions")
			exit(1)
예제 #8
0
 def testSampleData(self):
     # Tests that the np array generated by the data_analysis function matches saved expected results
     csv_data = pd.read_csv(fname=SAMPLE_DATA_FILE_LOC)
     analysis_results = data_processing(csv_data)
     expected_results = np.loadtext(fname=os.path.join(TEST_DATA_DIR, "expected_data.csv"), delimiter=',')
     self.assertTrue((expected_results == analysis_results).all())
예제 #9
0
import numpy as np
from matplotlib import plot as plt

x = np.loadtext("random.dat")
plt.hist(x, bins=100)
plt.show()
import numpy
filename = 'indian-diabities.data.csv'
raw_data = open(filename, 'r')
data = numpy.loadtext(raw_data, delimiter = ',')

print("numpy loadtext : ", data.shape)
raw_data.close()
##########################################################################################
# Settings
##########################################################################################

# Number of neurons in each layer.
#
N1 = 28 ** 2
N2 = 500
N3 = 500
N4 = 500
N5 = 10

# Load neural network parameters.
#
b1  = np.loadtext("bin/train_b1.csv")
W12 = np.loadtext("bin/train_W12.csv")
b2  = np.loadtext("bin/train_b2.csv")
W23 = np.loadtext("bin/train_W23.csv")
b3  = np.loadtext("bin/train_b3.csv")
W34 = np.loadtext("bin/train_W34.csv")
b4  = np.loadtext("bin/train_b4.csv")
W45 = np.loadtext("bin/train_W45.csv")
b5  = np.loadtext("bin/train_b5.csv")

##########################################################################################
# Methods
##########################################################################################

# Activation functions.
#
예제 #12
0
import numpy as np 

data = np.loadtext(
   fname = 'data/inflammation-01.csv'
   delimiter = ','
)

min_inflammation = np.min(
   data,
     axis = 0
)
 plt.plot(min_inflammation)

예제 #13
0
파일: Analise2.py 프로젝트: vss-2/Intro_DS
    elif (valIMC < 17):
        return str(valIMC) + ': Magreza moderada'
    elif (valIMC < 18.5):
        return str(valIMC) + ': Magreza leve'
    elif (valIMC < 25):
        return str(valIMC) + ': Saudavel'
    elif (valIMC < 30):
        return str(valIMC) + ': Sobrepeso'
    elif (valIMC < 35):
        return str(valIMC) + ': Obesidade Grau I'
    elif (valIMC < 40):
        return str(valIMC) + ': Obesidade Grau II (Severa)'
    else:
        return str(valIMC) + ': Obesidade Grau III (Morbida)'


# Os parametros sao:
# Local do arquivo
# Delimitador usado la no gerador
# Se houver mais de uma variavel para devemos "desempacotalas", e ha, entao True
# Tipo de dado

localArquivo = r'%s' % os.getcwd().replace('\\', '/') + '/peso.csv'
altura, peso, forca = np.loadtext(localArquivo + '/peso.csv',
                                  delimiter=';',
                                  unpack=True,
                                  dtype='float')

# Se pedirmos para printar, observer que saira tudo organizado
print(altura)
"""

"""
# Importing the KERAS Sequential model.

from keras.models import Sequentialfrom 
from keras.layers import Dense
import numpy

# Initailizing a seed value to an integer... I wonder why they choose 7
seed = 7

numpy.random.seed(seed);

# Loading the data set - they are using the PIMA Diabetes dataset... Do I Have access to this dataset?
dataset = numpy.loadtext(); # we'll need to handle this in some way.

# loading the input values to x and label values y using slicing...
x = datasett[:,0:8] # probably some kind of local definition.
y = dataset][:, 8]  # see above.

# Initializing the Sequential model from KERASmodel = Sequential()


# creatin a 16 neuron hidden layer with Linear Rectified activation function... pretty cool
model.add(Dense(16, input_dim=8, int='uniform', activation='relu'))

# creating an 8 neuron hidden layer
model.add(Dense(8, init='uniform',activation='relu'))

# adding an output layer.
        cost_val, _ = sess.run([cost, train], feed_dict={X: x_data, Y: y_data})
        if step % 200 == 0:
            print(step, cost_val)  # Finish Training

    # Accuracy report
    h, c, a = sess.run([hypothesis, predicted, accuracy],
                       feed_dict={
                           X: x_data,
                           Y: y_data
                       })
    print("\nHypothesis: ", h, "\nCorrect (Y): ", c, "\nAccuracy: ", a)

# ## Classifying diabetes 당뇨병
# : csv 파일을 불러오고 학습 후에 예측해보자

import numpy as np

xy = np.loadtext('data~ .csv', delimiter=',', dtype=np.float32)
# , 로 seperate하고 data type도 지정해줌

# Slicing - list에서 원하는 범위만큼 get
x_data = xy[:, 0:-1]
y_data = xy[:, [-1]]

# placeholder shape check하고 나머지 방법은 동일

X = tf.placeholder(tf.float32, shape=[None, 8])
Y = tf.placeholder(tf.float32, shape=[None, 1])

W = tf.Variable(tf.random_normal([8, 1]), name='weight')
b = tf.Variable(tf.random_normal([1]), name='bias')
예제 #16
0
def get_data(phosphors='./test_calib/spectrum_after.dat',
             fundamentals='./lms_cone_fundamentals.csv'):

    phosphors = np.loadtext()
예제 #17
0
    def readSE(self, output_file):
        '''
		Read in the given output file
		'''
        new_catalog = np.loadtext(output_file)
예제 #18
0
	def readSE(self,output_file):
		'''
		Read in the given output file
		'''
		new_catalog = np.loadtext(output_file)
예제 #19
0
#Load data
filenamevariable = 'filename.txt'
file = open(filenamevariable, mode = 'r')
#'r' is to read the file 
text = file.read()
file.close()
print(text)

#or to avoid having to close the file 
open('filename.txt', 'r') as file:
  print(file.read())

#Without a header. 
import numpy as np 
filenamevariable = 'filename.txt'
data = np.loadtext(filenamevariable, delimiter = ',')

#With a header
import numpy as np 
filenamevariable = 'filename.txt'
data = np.load.txt(filenamevariable, delimiter = ',', skiprows =1) 

#To load specific columns 
import numpy as np 
filenamevariable = 'filename.txt'
data = np.loadtxt(filenamevariable, delimiter = ',', skiprows = 1, usecols=[0,2])

#To load columns with specific data types 
import numpy as np 
filenamevariable = 'filename.txt'
data = np.loadtxt(filenamevariable, delimiter = ',', dtype = str)