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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
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)
    print(sum(range(5),-1))
    from numpy import *
    print(sum(range(5),-1))

# Exercise 25
    # Consider an integer vector Z, which of these expressions are legal?
    Z ** Z XXXXXXXXXXXXXXXXXXXX
    2 << Z >> 2 XXXXXXXXXXXXXXXXXXXX
    Z <- Z XXXXXXXXXXXXXXXXXXXX
    1j * Z XXXXXXXXXXXXXXXXXXXX
    Z / 1 / 1 XXXXXXXXXXXXXXXXXXXX
    Z <Z> Z

# Question 26
    # What are the results of the following expressions?
    np.array(0) // np.array(0) -- an integer
    np.array(0) // np.aray(0.) -- a floating point number
    np.array(0) / np.array(0) -- a floating point number
    np.array(0) / np.array(0.) -- a floating point number

# Question 27
    # How to round away from zero in a float array?
    Z = np.random.uniform(-10,+10,10)
    print(np.trunc(Z + np.copysign(0.5,Z)))

# Question 28
    # Extract the integer part of a random array using 5 different methods
    Z = np.random.uniform(0,10,10)

    print(Z - Z%1)
    print(np.floor(Z))