slicing

slicing behaviour question of a list of lists

I got a function like def f(): ... ... return [list1, list2] this returns a list of lists [[list1.item1,list1.item2,...],[list2.item1,list2.item2,...]] now when I do the following: for i in range(0,2):print f()[i][0:10] it works and print the lists sliced but if i do print f()[0:2][0:10] then it prints the lists ...

C++ polymorphism and slicing

The following code, prints out Derived Base Base But I need every Derived object put into User::items, call its own print function, but not the base class one. Can I achieve that without using pointers? If it is not possible, how should I write the function that deletes User::items one by one and frees memory, so that there should not...

Python slicing a string using space characters and a maximum length

I'd like to slice a string up in a similar way to .split() (so resulting in a list) but in a more intelligent way: I'd like it to split it into chunks that are up to 15 characters, but are not split mid word so: string = 'A string with words' [splitting process takes place] list = ('A string with','words') The string in this example...

Slicing a time range into parts

First question. Be gentle. I'm working on software that tracks technicians' time spent working on tasks. The software needs to be enhanced to recognize different billable rate multipliers based on the day of the week and the time of day. (For example, "Time and a half after 5 PM on weekdays.") The tech using the software is only requi...

References and the Slicing Problem

I don't have my Effective C++ with me and this is bugging me so much that I have to ask for my own sanity. Given class Foo : public Bar{} void MyFunc(Bar &_input); If I pass in a Foo, am I tangling with the slicing problem or have I avoided it? ...

how to convert a python slicing operation into java code

Hi, I have this code line: x and k are int. lm is an array lz=[f(x,lm[:j]+lm[j+1:],k) for j in range(n)] My question is: I want to convert the above line into Java... I have created an lm array in Java, but I am thinking of making it an arraylist to avoid the problem of the array length. I know that for instanse lm is [1, 4, 1, 9]...

Python: Implementing slicing in __getitem__

I am trying to implement slice functionality for a class I am making that creates a vector representation. I have this code so far, which I believe will properly implement the slice but whenever I do a call like v[4] where v is a vector python returns an error about not having enough parameters. So I am trying to figure out how to defin...

Python Numpy Structured Array (recarray) assigning values into slices

Hi, The following example shows what I want to do: >>> test rec.array([(0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0)], dtype=[('ifAction', '|i1'), ('ifDocu', '|i1'), ('ifComedy', '|i1')]) >>> test[['ifAction', 'ifDocu']][0] (0, 0) >>> test[['ifAction', 'ifDocu']][0]...

PSD slicing good practices

Hello guys, I'm managing the development of a website (new job) and we are currently on the slicing phase of the template, and I hear a lot of things of what we should and should not do while slicing... so what are the good practices you experienced developers do? What formats should the images be? Html conformation level (strict, trans...

slice (unsorted) array at value in python

Given the array a = [1,1,12,3,5,8,13,21] I can slice off the first 3 elements like a[:3] giving [1,1,2]. What I want is to slice off up to the element of vlaue i (e.g. if i=8 I want [1,1,12,3,5,8] or [1,1,12,3,5] (I can work with either)). This works: return a[:a.index(i)] but only if I give it a value that's in the array. Is ther...

Slicing python lists

Hi If I have a list of say 'n' elements (each element is a single byte ) which represents a rectangular 2d matrix, how can I split this into rectangles of say w * h, starting from the first element of the list , just using the python standard functions for example l = [ 1,2,3,4,5,6,7,8,9,10, 11,12,13,14,15....20. 21,22,2...

Improving pure Python prime sieve by recurrence formula

I am trying to optimize further the champion solution in prime number thread by taking out the complex formula for sub-list length. len() of the same subsequence is too slow as len is expensive and generating the subsequence is expensive. This looks to slightly speed up the function but I could not yet take away the division, though I do...

How to "slice" a POJO

I'm borrowing the "slice" meaning from C++. Let's say I hava a simple POJO that's persisted via Hibernate: class Person { private long id; private String name; ... // getters and setters here ... } Now, when I retrieve an object from the database I know it was "instrumented" by Hibernate (its real class is a Person-derived generated ...

Does std::move result in slicing?

For example, in unique_ptr<Derived> = new deriv; std::vector<unique_ptr<Base>>.push_back(std::move(deriv)); will deriv be sliced to type unique_ptr<Base>? ...

Slicing problem?

g++ -std=gnu++0x main.cpp In file included from main.cpp:6:0: CustArray.h: In constructor 'CustArray::CustArray()': CustArray.h:26:32: error: 'class Info' has no member named 'someInfo' make: *** [all] Error 1 /* * Info.h * */ #ifndef INFO_H_ #define INFO_H_ class Info { friend class CustArray; }; #endif /* INFO_H_ */ /* * ...

Yielding until all needed values are yielded, is there way to make slice to become lazy

Is there way to stop yielding when generator did not finish values and all needed results have been read? I mean that generator is giving values without ever doing StopIteration. For example, this never stops: (REVISED) from random import randint def devtrue(): while True: yield True answers=[False for _ in range(randint(1...

Python: Slice a 2d array into tiles

Hi I have a raw data file which I read into a byte buffer (a python string). Each data value represents an 8bit pixel of a 2d array representing an image. I know the width and height of this image. I would like to split the image into tiles so that each tiles area must be larger than a 'min tile area' (eg 1024 bytes) and smaller than '...

Why isn't this method call virtual like I was expecting?

Hello! I want to ask what happen, when I use virtual functions without pointers ? for example: #include <iostream> using namespace std; class Parent { public: Parent(int i) { } virtual void f() { cout<<"Parent"<<endl; } }; class Child : public Parent { public: Child(int i) : Parent(i) { } virtual void f() { Parent::f(); c...

Dynamic Data Slicing tools for Java and C++

I am looking for dynamic data slicing tools for Java and C++ that can detect both data and control dependencies in the program. I found out JSlice for Java and none for C/C++. Are there any other dynamic data slicing tools available for Java/C++/C ? ...

Tables to CSS....Layout sliced from Photoshop

I am messing around and created a neat web layout in photoshop. I then sliced it up and exported all of the Images and HTML to dreamweaver. However, it turns my layout into tables. This is a problem because I can't get it to fit all screen resolutions. Does anyone have a quick fix or some advice on how to get my slicing converted to CSS?...