当前位置: 首页>>代码示例>>Python>>正文


Python Stream.extend方法代码示例

本文整理汇总了Python中Stream.Stream.extend方法的典型用法代码示例。如果您正苦于以下问题:Python Stream.extend方法的具体用法?Python Stream.extend怎么用?Python Stream.extend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Stream.Stream的用法示例。


在下文中一共展示了Stream.extend方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import extend [as 别名]
def test():

    x = Stream('x')

    y,z = max_min_of_windows_in_stream(x)

    y.set_name('y')
    z.set_name('z')

    check(y, [5])
    check(z, [3])
    
    x.extend([3,5])
    x.print_recent()
    y.print_recent()
    z.print_recent()
    print

    x.extend([11,15])
    x.print_recent()
    y.print_recent()
    z.print_recent()
    print

    check_empty()
开发者ID:alphaz99,项目名称:stream-ml-py,代码行数:27,代码来源:test_example_window_single_in_multi_out_stateless.py

示例2: test

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import extend [as 别名]
def test():

    x = Stream('x')

    y,z = exp_smooth_max_and_std_of_windows_in_stream(x)

    y.set_name('y')
    z.set_name('z')

    check(y, [1.6000000000000001, 4.3200000000000003])
    check(z, [0.65319726474218087, 0.78383671769061702])
    
    x.extend([1, 2, 3, 4, 5])
    x.print_recent()
    y.print_recent()
    z.print_recent()
    print

    x.extend([6, 12, 13, 14, 15])
    x.print_recent()
    y.print_recent()
    z.print_recent()
    print

    check_empty()
开发者ID:alphaz99,项目名称:stream-ml-py,代码行数:27,代码来源:test_example_window_single_in_multi_out_stateful.py

示例3: main

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import extend [as 别名]
def main():
    # Functions: list -> list
    def square(lst):
        return [v*v for v in lst]

    def double(lst):
        return [2*v for v in lst]

    def even(lst):
        return [v for v in lst if not v%2]

    # Functions: stream -> stream.
    # Each element of the output stream is f() applied to the corresponding
    # element of the input stream.
    stream_square = partial(stream_func, f_type='list', f=square, num_outputs=1)
    stream_double = partial(stream_func, f_type='list', f=double, num_outputs=1)
    stream_even = partial(stream_func, f_type='list', f=even, num_outputs=1)
    # Create stream x, and give it name 'x'.
    x = Stream('input')

    # u is the stream returned by stream_square(x)  and
    # v is the stream returned by stream_double(x)
    # w is the stream returned by stream_square(v) and
    #   so w could have been defined as:
    #   stream_square(stream_double(x))
    # a is the stream containing only even values of x
    u = stream_square(x)
    v = stream_double(x)
    w = stream_square(v)
    a = stream_even(x)

    # Give names to streams u, v, and w. This is helpful in reading output.
    u.set_name('square of input')
    v.set_name('double of input')
    w.set_name('square of double of input')
    a.set_name('even values in input')

    print
    print 'add [3, 5] to the tail of the input stream'
    # Add values to the tail of stream x.
    x.extend([3, 5])

    # Print the N most recent values of streams x, u, v, w.
    x.print_recent()
    u.print_recent()
    v.print_recent()
    w.print_recent()
    a.print_recent()    

    print
    print 'add [2, 6] to the tail of the input stream'
    # Add more values to the tail of stream x.
    x.extend([2, 6])

    # Print the N most recent values of streams x, u, v, w.
    x.print_recent()
    u.print_recent()
    v.print_recent()
    w.print_recent()
    a.print_recent()
开发者ID:alphaz99,项目名称:stream-ml-py,代码行数:62,代码来源:example_list_single_in_single_out_stateless.py

示例4: main

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import extend [as 别名]
def main():
    def max_of_std(lst, state):
        a = np.array(lst)
        state = max(a.std(), state)
        return (state, state)
    print "example_1"
    print "example function from list to value: mean_and_sigma() "
    window_size = 10
    step_size = 10
    print "window_size = ", window_size
    print "step_size = ", step_size
    print ""

    x = Stream('x')
    # x is the in_stream.
    # sum() is the function on the window

    z = stream_func(x, f_type='window', f=max_of_std, num_outputs=1, state=0.0,
                    window_size=window_size, step_size=step_size)

    z.set_name('z')
 

    x.extend([random.random() for i in range(30)])
    x.print_recent()
    z.print_recent()
开发者ID:alphaz99,项目名称:stream-ml-py,代码行数:28,代码来源:example_window_single_in_single_out_stateful.py

示例5: main

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import extend [as 别名]
def main():

    def mean_of_window(stream):

        def mean(lst, state):
            sum_window, next_value_dropped = state
            if sum_window is None:
                sum_window = sum(lst)
            else:
                sum_window = sum_window + lst[-1] - next_value_dropped
            mean = sum_window/len(lst)
            next_value_dropped = lst[0]
            state = (sum_window, next_value_dropped)
            return (mean, state)

        return stream_func(
            inputs=stream,
            f_type='window',
            f=mean,
            num_outputs=1,
            state=(None, None),
            window_size=2,
            step_size=2)


    def max_of_std(lst, state):
        a = np.array(lst).std()
        if a > state:
            state = a
            return (a, state)
        else:
            return (_no_value, state)
        

    x = Stream('x')
    # x is the input stream.


    g = partial(stream_func, f_type='window',
                f=max_of_std,
                num_outputs=1, state=0.0,
                window_size=10, step_size=10)

    y = g(x)
    z = g(y)
    means = mean_of_window(x)

    y.set_name('y')
    z.set_name('z')
    means.set_name('means')

    x.extend([random.random() for i in range(30)])
    x.print_recent()
    y.print_recent()
    z.print_recent()
    means.print_recent()
开发者ID:alphaz99,项目名称:stream-ml-py,代码行数:58,代码来源:example_window_single_in_single_out_stateful.py

示例6: main

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import extend [as 别名]
def main():
    # Functions: list -> list of lists
    def even_odd(list_of_integers):
        evens_list = [n for n in list_of_integers if not n%2]
        odds_list = [n for n in list_of_integers if n%2]
        return (evens_list, odds_list)

    # Functions: stream -> stream.
    # The n-th element of the output stream is f() applied to the n-th
    # elements of each of the input streams.
    # Function mean is defined above, and functions sum and max are the
    # standard Python functions.
    stream_even_odd = partial(stream_func, f_type='list', f=even_odd, num_outputs=2)

    # Create stream x, and give it name 'x'.
    x = Stream('input_0')

    # u is the stream returned by stream_sum([x,y])  and
    # v is the stream returned by stream_max([x,y])
    # w is the stream returned by stream_mean([x,y]).
    # u[i] = sum(x[i],y[i])
    # v[i] = max(x[i],y[i])
    # w[i] = mean(x[i],y[i])    
    evens, odds = stream_even_odd(x)

    # Give names to streams u, v, and w. This is helpful in reading output.
    evens.set_name('even numbers in x')
    odds.set_name('odd numbers in x')

    print
    print 'Adding [3, 5, 8] to input stream'
    # Add values to the tail of stream x.
    x.extend([3, 5, 8])

    # Print recent values of the streams
    print 'recent values of input streams'
    x.print_recent()

    print 'recent values of output streams'
    evens.print_recent()
    odds.print_recent()


    print
    print 'Adding [4, 6, 2, 1] to the input stream'
    # Add more values to the tail of stream x.
    x.extend([4, 6, 2, 1])

    # Print recent values of the streams
    print 'recent values of input streams'
    x.print_recent()

    print 'recent values of output streams'
    evens.print_recent()
    odds.print_recent()
开发者ID:alphaz99,项目名称:stream-ml-py,代码行数:57,代码来源:example_list_single_in_multi_out_stateless.py

示例7: test

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import extend [as 别名]
def test():

    x = Stream('x')
    y = Stream('y')

    
    z = sum_diffs_means_of_windows([x,y])
    
    z.set_name('z')

    check(z, [1.0])
    
    x.extend([3,5])
    y.extend([2])
    x.print_recent()
    y.print_recent()
    z.print_recent()
    print

    x.extend([11,15])
    y.extend([4, -10, -12])
    x.print_recent()
    y.print_recent()
    z.print_recent()
    print

    check_empty()
开发者ID:alphaz99,项目名称:stream-ml-py,代码行数:29,代码来源:test_example_window_multi_in_single_out_stateful.py

示例8: main

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import extend [as 别名]
def main():
    def sum_diff_of_means(list_of_two_lists, cumulative):
        a, b = list_of_two_lists
        cumulative += np.mean(a) - np.mean(b)
        return (cumulative, cumulative)
    x = Stream('x')
    y = Stream('y')
    z = stream_func([x,y], f_type='window', f=sum_diff_of_means,
                    num_outputs=1, state = 0,
                    window_size=2, step_size=2)
    z.set_name('z')
    
    x.extend([3,5])
    y.extend([2])
    x.print_recent()
    y.print_recent()
    z.print_recent()
    print

    x.extend([11,15])
    y.extend([4, -10, -12])
    x.print_recent()
    y.print_recent()
    z.print_recent()
    print
开发者ID:alphaz99,项目名称:stream-ml-py,代码行数:27,代码来源:example_window_multi_in_single_out_stateful.py

示例9: test

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import extend [as 别名]
def test():

    # Create stream x, and give it name 'x'.
    x = Stream('input_0')

    # u is the stream returned by stream_sum([x,y])  and
    # v is the stream returned by stream_max([x,y])
    # w is the stream returned by stream_mean([x,y]).
    # u[i] = sum(x[i],y[i])
    # v[i] = max(x[i],y[i])
    # w[i] = mean(x[i],y[i])    
    evens, odds = stream_even_odd(x)

    # Give names to streams u, v, and w. This is helpful in reading output.
    evens.set_name('even numbers in x')
    odds.set_name('odd numbers in x')

    check(evens, [8, 4, 6, 2])
    check(odds, [3,5])

    print
    print 'Adding [3, 5, 8], [1, 7, 2], [2, 3] to 3 input streams'
    # Add values to the tail of stream x.
    x.extend([3, 5, 8])

    # Print recent values of the streams
    print 'recent values of input streams'
    x.print_recent()

    print 'recent values of output streams'
    evens.print_recent()
    odds.print_recent()


    print
    print 'Adding [4, 6, 2], [2, 3, 8], [5, 3, 0, -1] to 3 input streams'
    # Add more values to the tail of stream x.
    x.extend([4, 6, 2])

    # Print recent values of the streams
    print 'recent values of input streams'
    x.print_recent()

    print 'recent values of output streams'
    evens.print_recent()
    odds.print_recent()

    check_empty()
开发者ID:alphaz99,项目名称:stream-ml-py,代码行数:50,代码来源:test_example_element_single_in_multi_out_stateless.py

示例10: test

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import extend [as 别名]
def test():

    # Create stream x, and give it name 'x'.
    x = Stream('input_0')

    id_0_average, id_1_average = stream_split_by_sensor_id(x)

    # Give names to streams u, v, and w. This is helpful in reading output.
    id_0_average.set_name('average of id_0 sensors in x')
    id_1_average.set_name('average of id_1 sensors in x')

    check(id_0_average, [2.0, 3.0, 5.0, 4.0, 4.0])
    check(id_1_average, [5.0, 3.0, 3.0, 4.0, 5.0, 6.0])

    print
    print 'Adding ([(0,2), (0,4), (1,5), (1,1), (0,9)]'
    print 'to the input stream.'
    # Add values to the tail of stream x.
    x.extend([(0,2), (0,4), (1,5), (1,1), (0,9)])

    # Print recent values of the streams
    print
    print 'recent values of input streams'
    x.print_recent()

    print
    print 'recent values of output streams'
    id_0_average.print_recent()
    id_1_average.print_recent()

    print
    print
    print 'Adding ([(1,3), (1,7), (0,1), (1,9), (1,11), (0,4)])'
    print 'to the input stream.'
    # Add values to the tail of stream x.
    x.extend([(1,3), (1,7), (0,1), (1,9), (1,11), (0,4)])

    # Print recent values of the streams
    print 'recent values of input streams'
    print
    x.print_recent()

    print 'recent values of output streams'
    print
    id_0_average.print_recent()
    id_1_average.print_recent()

    check_empty()
开发者ID:alphaz99,项目名称:stream-ml-py,代码行数:50,代码来源:test_example_element_single_in_multi_out_stateful.py

示例11: test

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import extend [as 别名]
def test():
    in_1 = Stream(name='in_1')
    in_2 = Stream(name='in_2')
    out_1 = Stream(name='out_1')
    out_2 = Stream(name= 'out_2')
    out_1.print_recent()

    check(out_1, [13, 14, 15])
    check(out_2, [3, 4, 5])
    echo([in_1, in_2], [out_1, out_2])
    in_1.extend([3, 4, 5])
    in_2.extend([13, 14, 15])
    out_1.print_recent()
    out_2.print_recent()

    check_empty()
开发者ID:alphaz99,项目名称:stream-ml-py,代码行数:18,代码来源:test_example_agent_many_to_many.py

示例12: main

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import extend [as 别名]
def main():
    b, a = butter_bandpass(lowcut=0.1, highcut=5.0, fs=50, order=5)
    y = np.zeros(len(a)-1)
    state = (b, a, y)
    filename = '20110111000000.2D.OBS34.SXZ.npy'
    data_array = np.load(filename)
    print 'len(data_array)', len(data_array)
    data_array = data_array[:1000000]
    x = Stream('x')
    print 'a', a
    print 'b', b
    y = stream_func(x, f_type='window', f=linear_filter, num_outputs=1,
                    state=state, window_size=len(b), step_size=1)
    x.extend(data_array)
    y.set_name('y')
    plt.plot(y.recent[5000:y.stop])
    plt.show()
    plt.close()
开发者ID:alphaz99,项目名称:stream-ml-py,代码行数:20,代码来源:LinearFilter.py

示例13: test

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import extend [as 别名]
def test():
    in_1 = Stream(name='in_1')
    out_1 = Stream(name='out_1')
    out_2 = Stream(name= 'out_2')

    check(out_1, [4, 8])
    check(out_2, [3, 5])

    stream_agent(
        inputs=in_1,
        outputs=[out_1, out_2],
        f_type='element',
        f=number_even_odd)
    in_1.extend([3, 4, 5, 8])
    out_1.print_recent()
    out_2.print_recent()

    check_empty()
开发者ID:alphaz99,项目名称:stream-ml-py,代码行数:20,代码来源:test_example_agent_split.py

示例14: main

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import extend [as 别名]
def main():
    # EXAMPLE FUNCTIONS ON WINDOWS
    # Functions have a single input: a list
    # which is the list of values in a window.
    # Functions return a scalar value, _no_value
    # or a list, _multivalue().

    min_window_size = 3
    max_window_size = 7
    step_size = 2

    input_stream = Stream('in')
    output_stream = Stream('out')

    current_window_size = 0
    steady_state = False
    reset = False
    state = [current_window_size, steady_state, reset]

    def f(lst, state):
        if sum(lst) > 100:
            # state[2] is set to True to reset the window
            state[2] = True
        return (lst, state)

    dynamic_window_agent(
        f, input_stream, output_stream, state,
        min_window_size, max_window_size, step_size)

    ## input_stream.extend(range(5))

    for i in range(0, 10):
        input_stream.extend([i])
        input_stream.print_recent()
        output_stream.print_recent()
        print "\n"

    for i in range(2,4,1):
        input_stream.extend(range(10*i,10*i+5,1))
        print
        input_stream.print_recent()
        print
        output_stream.print_recent()
        print
开发者ID:alphaz99,项目名称:stream-ml-py,代码行数:46,代码来源:example_Rahul.py

示例15: test

# 需要导入模块: from Stream import Stream [as 别名]
# 或者: from Stream.Stream import extend [as 别名]
def test():

    # Create stream x and give it names 'x'.
    x = Stream('input')

    # v is the stream returned by stream_cumulative(x)  and
    # w is the stream returned by stream_cumulative(v).
    v = stream_cumulative(x)
    w = stream_cumulative(v)
    # avg is the stream returned by stream_average(x)
    avg = stream_average(x)

    # Give names to streams. This is helpful in reading output.
    v.set_name('cumulative sum of input')
    w.set_name('cumulative sum of cumulative sum of input')
    avg.set_name('average of input')

    check(v, [3, 8, 18, 20, 25, 36])
    check(w, [3, 11, 29, 49, 74, 110])
    check(avg, [3.0, 4.0, 6.0, 5.0, 5.0, 6.0])

    print
    print 'add values [3, 5, 10] to the tail of the input stream.'
    # Add values to the tail of stream x.
    x.extend([3, 5, 10])

    # Print the N most recent values of streams x, v, w.
    x.print_recent()
    v.print_recent()
    w.print_recent()
    avg.print_recent()

    print
    print 'add values [2, 5, 11] to the tail of the input stream.'
    # Add more values to the tail of stream x.
    x.extend([2, 5, 11])

    # Print the N most recent values of streams x, v, w.
    x.print_recent()
    v.print_recent()
    w.print_recent()
    avg.print_recent()

    check_empty()
开发者ID:alphaz99,项目名称:stream-ml-py,代码行数:46,代码来源:test_example_element_single_in_single_out_stateful.py


注:本文中的Stream.Stream.extend方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。