def getPointsPath(x1,y1,x2,y2,step,width,height,p1=1,p2=1): # start with empty path path=[] lastpoint=(-1,-1) # calculate straight line distance between coords delta_x=x2-x1 delta_y=y2-y1 delta_p=p2-p1 h=math.hypot(abs(delta_x),abs(delta_y)) # if distance between is too small, just return coord 2 if h < step*2: path.append((x2,y2,p2)) return path # calculate intermediate coords intermediate_points=numpy.arange(step,h,step) for point in intermediate_points: newx=int(x1+(delta_x*point/h)) newy=int(y1+(delta_y*point/h)) newp=p1+(delta_p*point/h) # make sure coords fall in widht and height restrictions if newx>=0 and newx<width and newy>=0 and newy<height: # only add point if it was different from previous one if newx!=lastpoint[0] or newy!=lastpoint[1]: lastpoint=(newx,newy,newp) path.append(lastpoint) if x2>=0 and x2<width and y2>=0 and y2<height: path.append((x2,y2,p2)) return path
def run_experiment(niter=100): K = 100 results = [] for _ in xrange(niter): mat = np.random.randn(K, K) max_eigenvalue = np.abs(eigvals(mat).max()) results.append(max_eigenvalue) return results
def getPointsPath(x1,y1,x2,y2,linestep,width,height,p1=1,p2=1): # start with a blank list path=[] lastpoint=(x1,y1) # calculate straight line distance between coords delta_x=x2-x1 delta_y=y2-y1 delta_p=p2-p1 h=math.hypot(abs(delta_x),abs(delta_y)) # calculate intermediate coords intermediate_points=numpy.arange(linestep,h,linestep) if len(intermediate_points)==0: return path pstep=delta_p/len(intermediate_points) newp=p1 for point in intermediate_points: newx=x1+(delta_x*point/h) newy=y1+(delta_y*point/h) newp=newp+pstep # make sure coords fall in widht and height restrictions if newx>=0 and newx<width and newy>=0 and newy<height: # make sure we don't skip a point #if step==0 int(newx)!=int(lastpoint[0]) and int(newy)!=int(lastpoint[1]): # print "skipped from point:", lastpoint, "to:", newx,newy # only add point if it was different from previous one #if int(newx)!=int(lastpoint[0]) or int(newy)!=int(lastpoint[1]): lastpoint=(newx,newy,newp) path.append(lastpoint) return path
import NumPy as np # Converting NumPy array to byte format byte_output = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]).tobytes() # Converting byte format back to NumPy array array_format = np.frombuffer(byte_output)
from __future__ import absolute_import, division, print_function, unicode_literals import tensorflow as tf import NumPy as np import logging logger = tf.get_logger() logger.setLevel(logging.ERROR) celsius_q = np.array([-40, -10, 0, 8, 15, 22, 38], dtype=float) farheneit_a = np.array([-40, 14, 32, 46, 59, 72, 100], dtype=float) for i, c in enumerate(celsius_q): print("{} degrees Celsius = {} degrees farenheit".format(c, farheneit_a[i])) slope = 1 intercept = 1 learning_rate = 0.1 ''' for i in range(epochs): curr_values = [] for c in celsius_q: curr_values.append(slope*celsisu+slope) for i in range(len(curr_values)): error = curr_values[i]-celsius_q[i] ''' # creating the underlying neural network to identify the relationships IO = tf.keras.layers.Dense(units=1,input_shape=1)
import tensorflow as tf import matplotlib.pyplot as plt ##sess = tf.InteractiveSession(config=tf.ConfigProto(log_device_placement=True)) ## ##x = tf.constant([t for t in range(100)], shape=(1,100), dtype=tf.float32) ##y = tf.constant(4, dtype=tf.float32) ## ##out = tf.scalar_mul(y,x) ## ## ## ##sess.run(tf.global_variables_initializer()) # Creates a graph. ##with tf.device("/device:GPU:0"): ## a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a') ## b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b') ## c = tf.matmul(a, b) ### Creates a session with log_device_placement set to True. ##sess = tf.Session(config=tf.ConfigProto(log_device_placement=True)) ### Runs the op. ##print(sess.run(c)) a = np.array([1, 2, 3, 4, 5, 6, -34]) b = np.divide(a, 2) print(a, b) a = np.array([1, 2, 3, 4, 5, 6, -34]) b = np.divide(a, 3) print(a, b)
def print_NumPy(): x = np.arange(12, 38)
#_*_encoding:utf-8_*_ #!/usr/bin/env python import NumPy as np a = np.arange(15).reshape(3, 5) print a
######################################## ######################################## # http://www.labri.fr/perso/nrougier/teaching/numpy.100/ ######################################## # Exercise 1 # Import the NumPy package under the name np import NumPy as np # Exercise 2 # Print the NumPy version and the configuration print(np.__version__) np.show_config() # Exercise 3 # Create a null vector of size 10 Z = np.zeros(10) print(Z) # Exercise 4 # How to get the documentation of the numpy add function # from the command line python -c "import numpy; numpy.info(numpy.add)" # Exercise 5 # Create a null vector of size 10 but the fifth value which is 1 Z = np.zeros(10) Z[4]=1