GUI and Desktop Applications int64 0 1 | A_Id int64 5.3k 72.5M | Networking and APIs int64 0 1 | Python Basics and Environment int64 0 1 | Other int64 0 1 | Database and SQL int64 0 1 | Available Count int64 1 13 | is_accepted bool 2
classes | Q_Score int64 0 1.72k | CreationDate stringlengths 23 23 | Users Score int64 -11 327 | AnswerCount int64 1 31 | System Administration and DevOps int64 0 1 | Title stringlengths 15 149 | Q_Id int64 5.14k 60M | Score float64 -1 1.2 | Tags stringlengths 6 90 | Answer stringlengths 18 5.54k | Question stringlengths 49 9.42k | Web Development int64 0 1 | Data Science and Machine Learning int64 1 1 | ViewCount int64 7 3.27M |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | 1,659,332 | 0 | 0 | 0 | 0 | 3 | false | 14 | 2008-08-07T18:47:00.000 | 5 | 4 | 0 | Does anyone have experience creating a shared library in MATLAB? | 5,136 | 0.244919 | python,c,matlab | One thing to remember is that the Matlab compiler does not actually compile the Matlab code into native machine instructions. It simply wraps it into a standalone executable or a library with its own runtime engine that runs it. You would be able to run your code without Matlab installed, and you would be able to int... | A researcher has created a small simulation in MATLAB and we want to make it accessible to others. My plan is to take the simulation, clean up a few things and turn it into a set of functions. Then I plan to compile it into a C library and use SWIG to create a Python wrapper. At that point, I should be able to call the... | 0 | 1 | 2,313 |
1 | 138,534 | 0 | 0 | 0 | 0 | 3 | false | 14 | 2008-08-07T18:47:00.000 | 2 | 4 | 0 | Does anyone have experience creating a shared library in MATLAB? | 5,136 | 0.099668 | python,c,matlab | I'd also try ctypes first.
Use the Matlab compiler to compile the code into C.
Compile the C code into a DLL.
Use ctypes to load and call code from this DLL
The hardest step is probably 1, but if you already know Matlab and have used the Matlab compiler, you should not have serious problems with it. | A researcher has created a small simulation in MATLAB and we want to make it accessible to others. My plan is to take the simulation, clean up a few things and turn it into a set of functions. Then I plan to compile it into a C library and use SWIG to create a Python wrapper. At that point, I should be able to call the... | 0 | 1 | 2,313 |
1 | 5,302 | 0 | 0 | 0 | 0 | 3 | true | 14 | 2008-08-07T18:47:00.000 | 3 | 4 | 0 | Does anyone have experience creating a shared library in MATLAB? | 5,136 | 1.2 | python,c,matlab | I won't help much but I remember that I was able to wrap a MATLAB simulation into DLL and then call it from a Delphi app. It worked really well. | A researcher has created a small simulation in MATLAB and we want to make it accessible to others. My plan is to take the simulation, clean up a few things and turn it into a set of functions. Then I plan to compile it into a C library and use SWIG to create a Python wrapper. At that point, I should be able to call the... | 0 | 1 | 2,313 |
0 | 138,886 | 0 | 1 | 0 | 0 | 1 | false | 14 | 2008-09-08T08:25:00.000 | -2 | 7 | 0 | Can parallel traversals be done in MATLAB just as in Python? | 49,307 | -0.057081 | python,arrays,matlab,for-loop | for loops in MATLAB used to be slow, but this is not true anymore.
So vectorizing is not always the miracle solution. Just use the profiler, and tic and toc functions to help you identify possible bottlenecks. | Using the zip function, Python allows for loops to traverse multiple sequences in parallel.
for (x,y) in zip(List1, List2):
Does MATLAB have an equivalent syntax? If not, what is the best way to iterate over two parallel arrays at the same time using MATLAB? | 0 | 1 | 7,417 |
0 | 150,318 | 0 | 1 | 0 | 0 | 1 | false | 19 | 2008-09-29T19:31:00.000 | 9 | 2 | 0 | What is the difference between __reduce__ and __reduce_ex__? | 150,284 | 1 | python,pickle | __reduce_ex__ is what __reduce__ should have been but never became. __reduce_ex__ works like __reduce__ but the pickle protocol is passed. | I understand that these methods are for pickling/unpickling and have no relation to the reduce built-in function, but what's the difference between the 2 and why do we need both? | 0 | 1 | 9,908 |
1 | 1,568,711 | 0 | 0 | 0 | 0 | 1 | false | 12 | 2008-10-04T05:36:00.000 | 3 | 3 | 0 | 2D animation in Python | 169,810 | 0.197375 | python,animation,2d | You can try pygame, its very easy to handle and similar to SDL under c++ | I'm writing a simulator in Python, and am curious about options and opinions regarding basic 2D animations. By animation, I'm referring to rendering on the fly, not displaying prerendered images.
I'm currently using matplotlib (Wxagg backend), and it's possible that I'll be able to continue using it, but I suspect it w... | 0 | 1 | 29,957 |
0 | 181,127 | 0 | 1 | 0 | 0 | 13 | false | 53 | 2008-10-07T19:11:00.000 | 5 | 21 | 0 | What is MATLAB good for? Why is it so used by universities? When is it better than Python? | 179,904 | 0.047583 | python,matlab | Seems to be pure inertia. Where it is in use, everyone is too busy to learn IDL or numpy in sufficient detail to switch, and don't want to rewrite good working programs. Luckily that's not strictly true, but true enough in enough places that Matlab will be around a long time. Like Fortran (in active use where i wor... | I've been recently asked to learn some MATLAB basics for a class.
What does make it so cool for researchers and people that works in university?
I saw it's cool to work with matrices and plotting things... (things that can be done easily in Python using some libraries).
Writing a function or parsing a file is just pain... | 0 | 1 | 200,558 |
0 | 1,890,839 | 0 | 1 | 0 | 0 | 13 | false | 53 | 2008-10-07T19:11:00.000 | 2 | 21 | 0 | What is MATLAB good for? Why is it so used by universities? When is it better than Python? | 179,904 | 0.019045 | python,matlab | Matlab is good at doing number crunching. Also Matrix and matrix manipulation. It has many helpful built in libraries(depends on the what version) I think it is easier to use than python if you are going to be calculating equations. | I've been recently asked to learn some MATLAB basics for a class.
What does make it so cool for researchers and people that works in university?
I saw it's cool to work with matrices and plotting things... (things that can be done easily in Python using some libraries).
Writing a function or parsing a file is just pain... | 0 | 1 | 200,558 |
0 | 179,910 | 0 | 1 | 0 | 0 | 13 | false | 53 | 2008-10-07T19:11:00.000 | 13 | 21 | 0 | What is MATLAB good for? Why is it so used by universities? When is it better than Python? | 179,904 | 1 | python,matlab | MATLAB is great for doing array manipulation, doing specialized math functions, and for creating nice plots quick.
I'd probably only use it for large programs if I could use a lot of array/matrix manipulation.
You don't have to worry about the IDE as much as in more formal packages, so it's easier for students without ... | I've been recently asked to learn some MATLAB basics for a class.
What does make it so cool for researchers and people that works in university?
I saw it's cool to work with matrices and plotting things... (things that can be done easily in Python using some libraries).
Writing a function or parsing a file is just pain... | 0 | 1 | 200,558 |
0 | 179,932 | 0 | 1 | 0 | 0 | 13 | false | 53 | 2008-10-07T19:11:00.000 | 4 | 21 | 0 | What is MATLAB good for? Why is it so used by universities? When is it better than Python? | 179,904 | 0.038077 | python,matlab | The main reason it is useful in industry is the plug-ins built on top of the core functionality. Almost all active Matlab development for the last few years has focused on these.
Unfortunately, you won't have much opportunity to use these in an academic environment. | I've been recently asked to learn some MATLAB basics for a class.
What does make it so cool for researchers and people that works in university?
I saw it's cool to work with matrices and plotting things... (things that can be done easily in Python using some libraries).
Writing a function or parsing a file is just pain... | 0 | 1 | 200,558 |
0 | 180,012 | 0 | 1 | 0 | 0 | 13 | false | 53 | 2008-10-07T19:11:00.000 | 4 | 21 | 0 | What is MATLAB good for? Why is it so used by universities? When is it better than Python? | 179,904 | 0.038077 | python,matlab | One reason MATLAB is popular with universities is the same reason a lot of things are popular with universities: there's a lot of professors familiar with it, and it's fairly robust.
I've spoken to a lot of folks who are especially interested in MATLAB's nascent ability to tap into the GPU instead of working serially. ... | I've been recently asked to learn some MATLAB basics for a class.
What does make it so cool for researchers and people that works in university?
I saw it's cool to work with matrices and plotting things... (things that can be done easily in Python using some libraries).
Writing a function or parsing a file is just pain... | 0 | 1 | 200,558 |
0 | 181,295 | 0 | 1 | 0 | 0 | 13 | false | 53 | 2008-10-07T19:11:00.000 | 3 | 21 | 0 | What is MATLAB good for? Why is it so used by universities? When is it better than Python? | 179,904 | 0.028564 | python,matlab | I think you answered your own question when you noted that Matlab is "cool to work with matrixes and plotting things". Any application that requires a lot of matrix maths and visualisation will probably be easiest to do in Matlab.
That said, Matlab's syntax feels awkward and shows the language's age. In contrast, Pytho... | I've been recently asked to learn some MATLAB basics for a class.
What does make it so cool for researchers and people that works in university?
I saw it's cool to work with matrices and plotting things... (things that can be done easily in Python using some libraries).
Writing a function or parsing a file is just pain... | 0 | 1 | 200,558 |
0 | 181,492 | 0 | 1 | 0 | 0 | 13 | false | 53 | 2008-10-07T19:11:00.000 | 15 | 21 | 0 | What is MATLAB good for? Why is it so used by universities? When is it better than Python? | 179,904 | 1 | python,matlab | Hold everything. When's the last time you programed your calculator to play tetris? Did you actually think you could write anything you want in those 128k of RAM? Likely not. MATLAB is not for programming unless you're dealing with huge matrices. It's the graphing calculator you whip out when you've got Megabytes to Gi... | I've been recently asked to learn some MATLAB basics for a class.
What does make it so cool for researchers and people that works in university?
I saw it's cool to work with matrices and plotting things... (things that can be done easily in Python using some libraries).
Writing a function or parsing a file is just pain... | 0 | 1 | 200,558 |
0 | 193,386 | 0 | 1 | 0 | 0 | 13 | false | 53 | 2008-10-07T19:11:00.000 | 34 | 21 | 0 | What is MATLAB good for? Why is it so used by universities? When is it better than Python? | 179,904 | 1 | python,matlab | I've been using matlab for many years in my research. It's great for linear algebra and has a large set of well-written toolboxes. The most recent versions are starting to push it into being closer to a general-purpose language (better optimizers, a much better object model, richer scoping rules, etc.).
This past s... | I've been recently asked to learn some MATLAB basics for a class.
What does make it so cool for researchers and people that works in university?
I saw it's cool to work with matrices and plotting things... (things that can be done easily in Python using some libraries).
Writing a function or parsing a file is just pain... | 0 | 1 | 200,558 |
0 | 180,736 | 0 | 1 | 0 | 0 | 13 | false | 53 | 2008-10-07T19:11:00.000 | 3 | 21 | 0 | What is MATLAB good for? Why is it so used by universities? When is it better than Python? | 179,904 | 0.028564 | python,matlab | It's been some time since I've used Matlab, but from memory it does provide (albeit with extra plugins) the ability to generate source to allow you to realise your algorithm on a DSP.
Since python is a general purpose programming language there is no reason why you couldn't do everything in python that you can do in ma... | I've been recently asked to learn some MATLAB basics for a class.
What does make it so cool for researchers and people that works in university?
I saw it's cool to work with matrices and plotting things... (things that can be done easily in Python using some libraries).
Writing a function or parsing a file is just pain... | 0 | 1 | 200,558 |
0 | 181,274 | 0 | 1 | 0 | 0 | 13 | false | 53 | 2008-10-07T19:11:00.000 | 7 | 21 | 0 | What is MATLAB good for? Why is it so used by universities? When is it better than Python? | 179,904 | 1 | python,matlab | Personally, I tend to think of Matlab as an interactive matrix calculator and plotting tool with a few scripting capabilities, rather than as a full-fledged programming language like Python or C. The reason for its success is that matrix stuff and plotting work out of the box, and you can do a few very specific things... | I've been recently asked to learn some MATLAB basics for a class.
What does make it so cool for researchers and people that works in university?
I saw it's cool to work with matrices and plotting things... (things that can be done easily in Python using some libraries).
Writing a function or parsing a file is just pain... | 0 | 1 | 200,558 |
0 | 180,017 | 0 | 1 | 0 | 0 | 13 | false | 53 | 2008-10-07T19:11:00.000 | 6 | 21 | 0 | What is MATLAB good for? Why is it so used by universities? When is it better than Python? | 179,904 | 1 | python,matlab | I believe you have a very good point and it's one that has been raised in the company where I work. The company is limited in it's ability to apply matlab because of the licensing costs involved. One developer proved that Python was a very suitable replacement but it fell on ignorant ears because to the owners of those... | I've been recently asked to learn some MATLAB basics for a class.
What does make it so cool for researchers and people that works in university?
I saw it's cool to work with matrices and plotting things... (things that can be done easily in Python using some libraries).
Writing a function or parsing a file is just pain... | 0 | 1 | 200,558 |
0 | 179,912 | 0 | 1 | 0 | 0 | 13 | false | 53 | 2008-10-07T19:11:00.000 | 6 | 21 | 0 | What is MATLAB good for? Why is it so used by universities? When is it better than Python? | 179,904 | 1 | python,matlab | The most likely reason that it's used so much in universities is that the mathematics faculty are used to it, understand it, and know how to incorporate it into their curriculum. | I've been recently asked to learn some MATLAB basics for a class.
What does make it so cool for researchers and people that works in university?
I saw it's cool to work with matrices and plotting things... (things that can be done easily in Python using some libraries).
Writing a function or parsing a file is just pain... | 0 | 1 | 200,558 |
0 | 1,113,065 | 0 | 1 | 0 | 0 | 13 | false | 53 | 2008-10-07T19:11:00.000 | 4 | 21 | 0 | What is MATLAB good for? Why is it so used by universities? When is it better than Python? | 179,904 | 0.038077 | python,matlab | I know this question is old, and therefore may no longer be
watched, but I felt it was necessary to comment. As an
aerospace engineer at Georgia Tech, I can say, with no
qualms, that MATLAB is awesome. You can have it quickly
interface with your Excel spreadsheets to pull in data about
how high and fast rockets are fly... | I've been recently asked to learn some MATLAB basics for a class.
What does make it so cool for researchers and people that works in university?
I saw it's cool to work with matrices and plotting things... (things that can be done easily in Python using some libraries).
Writing a function or parsing a file is just pain... | 0 | 1 | 200,558 |
0 | 213,717 | 0 | 0 | 1 | 0 | 1 | false | 62 | 2008-10-17T05:30:00.000 | 1 | 7 | 0 | Python Inverse of a Matrix | 211,160 | 0.028564 | python,algorithm,matrix,linear-algebra,matrix-inverse | If you hate numpy, get out RPy and your local copy of R, and use it instead.
(I would also echo to make you you really need to invert the matrix. In R, for example, linalg.solve and the solve() function don't actually do a full inversion, since it is unnecessary.) | How do I get the inverse of a matrix in python? I've implemented it myself, but it's pure python, and I suspect there are faster modules out there to do it. | 0 | 1 | 125,109 |
0 | 346,873 | 0 | 0 | 0 | 0 | 1 | false | 2 | 2008-12-06T21:40:00.000 | 0 | 5 | 0 | Ticking function grapher | 346,823 | 0 | python,algorithm,math | Using deltaX
if deltax between 2 and 10 half increment
if deltax between 10 and 20 unit increment
if smaller than 2 we multiply by 10 and test again
if larger than 20 we divide
Then we get the position of the first unit or half increment on the width using xmin.
I still need to test this solution. | I am trying to figure out the following problem.
I am building Yet another math function grapher, The function is drawn on its predefined x,y range, that's all good.
Now I am working on the background and the ticking of X, Y axes (if any axes are shown).
I worked out the following.
I have a fixed width of 250 p
The ti... | 0 | 1 | 239 |
0 | 9,827,070 | 0 | 0 | 0 | 0 | 2 | false | 52 | 2008-12-09T13:15:00.000 | 4 | 9 | 0 | Weighted random selection with and without replacement | 352,670 | 0.088656 | python,algorithm,random,random-sample | The following is a description of random weighted selection of an element of a
set (or multiset, if repeats are allowed), both with and without replacement in O(n) space
and O(log n) time.
It consists of implementing a binary search tree, sorted by the elements to be
selected, where each node of the tree contains:
... | Recently I needed to do weighted random selection of elements from a list, both with and without replacement. While there are well known and good algorithms for unweighted selection, and some for weighted selection without replacement (such as modifications of the resevoir algorithm), I couldn't find any good algorithm... | 0 | 1 | 32,149 |
0 | 66,553,611 | 0 | 0 | 0 | 0 | 2 | false | 52 | 2008-12-09T13:15:00.000 | 1 | 9 | 0 | Weighted random selection with and without replacement | 352,670 | 0.022219 | python,algorithm,random,random-sample | This is an old question for which numpy now offers an easy solution so I thought I would mention it. Current version of numpy is version 1.2 and numpy.random.choice allows the sampling to be done with or without replacement and with given weights. | Recently I needed to do weighted random selection of elements from a list, both with and without replacement. While there are well known and good algorithms for unweighted selection, and some for weighted selection without replacement (such as modifications of the resevoir algorithm), I couldn't find any good algorithm... | 0 | 1 | 32,149 |
0 | 421,947 | 0 | 0 | 0 | 0 | 1 | false | 3 | 2009-01-07T01:12:00.000 | 1 | 5 | 0 | Are there any graph/plotting/anything-like-that libraries for Python 3.0? | 418,835 | 0.039979 | python,python-3.x,plot,graphing,scatter-plot | Maybe you can use Python Imaging Library (PIL).
Also have a look at PyX, but this library is meant to output to PDF, ... | As per the title. I am trying to create a simple scater plot, but haven't found any Python 3.0 libraries that can do it. Note, this isn't for a website, so the web ones are a bit useless. | 0 | 1 | 1,540 |
0 | 40,674,024 | 0 | 1 | 0 | 0 | 1 | false | 325 | 2009-01-23T18:34:00.000 | 4 | 11 | 0 | Shuffle an array with python, randomize array item order with python | 473,973 | 0.072599 | python,arrays,random,shuffle | In addition to the previous replies, I would like to introduce another function.
numpy.random.shuffle as well as random.shuffle perform in-place shuffling. However, if you want to return a shuffled array numpy.random.permutation is the function to use. | What's the easiest way to shuffle an array with python? | 0 | 1 | 285,289 |
0 | 555,159 | 0 | 0 | 0 | 0 | 1 | false | 0 | 2009-02-17T00:29:00.000 | 2 | 2 | 0 | Multiple output files | 555,146 | 0.197375 | python,file-io | I would open seven file streams as accumulating them might be quite memory extensive if it's a lot of data. Of course that is only an option if you can sort them live and don't first need all data read to do the sorting. | edit: Initially I was trying to be general but it came out vague. I've included more detail below.
I'm writing a script that pulls in data from two large CSV files, one of people's schedules and the other of information about their schedules. The data is mined and combined to eventually create pajek format graphs for ... | 0 | 1 | 593 |
0 | 556,961 | 0 | 0 | 1 | 0 | 1 | false | 11 | 2009-02-17T13:16:00.000 | 1 | 6 | 0 | Python list serialization - fastest method | 556,730 | 0.033321 | python,serialization,caching | cPickle will be the fastest since it is saved in binary and no real python code has to be parsed.
Other advantates are that it is more secure (since it does not execute commands) and you have no problems with setting $PYTHONPATH correctly. | I need to load (de-serialize) a pre-computed list of integers from a file in a Python script (into a Python list). The list is large (upto millions of items), and I can choose the format I store it in, as long as loading is fastest.
Which is the fastest method, and why?
Using import on a .py file that just contains th... | 0 | 1 | 8,359 |
0 | 570,197 | 0 | 0 | 0 | 0 | 1 | false | 1 | 2009-02-20T16:04:00.000 | 1 | 4 | 0 | Statistics with numpy | 570,137 | 0.049958 | python,numpy | In addition to df's answer, if you want to know the specific prices that are above the base prices, you can do:
prices[prices > (1.10 * base_prices)] | I am working at some plots and statistics for work and I am not sure how I can do some statistics using numpy: I have a list of prices and another one of basePrices. And I want to know how many prices are with X percent above basePrice, how many are with Y percent above basePrice.
Is there a simple way to do that using... | 0 | 1 | 1,834 |
0 | 20,666,684 | 0 | 1 | 0 | 0 | 1 | false | 22 | 2009-03-09T21:58:00.000 | 0 | 7 | 0 | Python equivalent to java.util.SortedSet? | 628,192 | 0 | python,data-structures | Do you have the possibility of using Jython? I just mention it because using TreeMap, TreeSet, etc. is trivial. Also if you're coming from a Java background and you want to head in a Pythonic direction Jython is wonderful for making the transition easier. Though I recognise that use of TreeSet in this case would not ... | Does anybody know if Python has an equivalent to Java's SortedSet interface?
Heres what I'm looking for: lets say I have an object of type foo, and I know how to compare two objects of type foo to see whether foo1 is "greater than" or "less than" foo2. I want a way of storing many objects of type foo in a list L, so th... | 1 | 1 | 9,278 |
0 | 13,611,588 | 0 | 0 | 0 | 0 | 4 | false | 10 | 2009-03-16T21:53:00.000 | 3 | 8 | 0 | Can a neural network be used to find a functions minimum(a)? | 652,283 | 0.07486 | python,artificial-intelligence,neural-network,minimization | Back-propagation works by minimizing the error. However, you can really minimize whatever you want. So, you could use back-prop-like update rules to find the Artificial Neural Network inputs that minimize the output.
This is a big question, sorry for the short answer. I should also add that my suggested approach sou... | I had been interested in neural networks for a bit and thought about using one in python for a light project that compares various minimization techniques in a time domain (which is fastest).
Then I realized I didn't even know if a NN is good for minimization. What do you think? | 0 | 1 | 7,231 |
0 | 652,348 | 0 | 0 | 0 | 0 | 4 | false | 10 | 2009-03-16T21:53:00.000 | 0 | 8 | 0 | Can a neural network be used to find a functions minimum(a)? | 652,283 | 0 | python,artificial-intelligence,neural-network,minimization | They're pretty bad for the purpose; one of the big problems of neural networks is that they get stuck in local minima. You might want to look into support vector machines instead. | I had been interested in neural networks for a bit and thought about using one in python for a light project that compares various minimization techniques in a time domain (which is fastest).
Then I realized I didn't even know if a NN is good for minimization. What do you think? | 0 | 1 | 7,231 |
0 | 652,327 | 0 | 0 | 0 | 0 | 4 | false | 10 | 2009-03-16T21:53:00.000 | 1 | 8 | 0 | Can a neural network be used to find a functions minimum(a)? | 652,283 | 0.024995 | python,artificial-intelligence,neural-network,minimization | The training process of a back-propagation neural network works by minimizing the error from the optimal result. But having a trained neural network finding the minimum of an unknown function would be pretty hard.
If you restrict the problem to a specific function class, it could work, and be pretty quick too. Neural n... | I had been interested in neural networks for a bit and thought about using one in python for a light project that compares various minimization techniques in a time domain (which is fastest).
Then I realized I didn't even know if a NN is good for minimization. What do you think? | 0 | 1 | 7,231 |
0 | 652,362 | 0 | 0 | 0 | 0 | 4 | true | 10 | 2009-03-16T21:53:00.000 | -5 | 8 | 0 | Can a neural network be used to find a functions minimum(a)? | 652,283 | 1.2 | python,artificial-intelligence,neural-network,minimization | Neural networks are classifiers. They separate two classes of data elements. They learn this separation (usually) by preclassified data elements. Thus, I say: No, unless you do a major stretch beyond breakage. | I had been interested in neural networks for a bit and thought about using one in python for a light project that compares various minimization techniques in a time domain (which is fastest).
Then I realized I didn't even know if a NN is good for minimization. What do you think? | 0 | 1 | 7,231 |
0 | 703,588 | 0 | 0 | 1 | 0 | 1 | false | 6 | 2009-03-31T22:03:00.000 | 0 | 4 | 0 | Most efficient way of loading formatted binary files in Python | 703,262 | 0 | python,input,binaryfiles | I found that array.fromfile is the fastest methods for homogeneous data. | I have binary files no larger than 20Mb in size that have a header section and then a data section containing sequences of uchars. I have Numpy, SciPy, etc. and each library has different ways of loading in the data. Any suggestions for the most efficient methods I should use? | 0 | 1 | 450 |
0 | 817,451 | 0 | 0 | 0 | 0 | 1 | true | 3 | 2009-04-24T10:30:00.000 | 0 | 3 | 0 | Twitter Data Mining: Degrees of separation | 785,327 | 1.2 | python,twitter,dump,social-graph | There was a company offering a dump of the social graph, but it was taken down and no longer available. As you already realized - it is kind of hard, as it is changing all the time.
I would recommend checking out their social_graph api methods as they give the most info with the least API calls. | What ready available algorithms could I use to data mine twitter to find out the degrees of separation between 2 people on twitter.
How does it change when the social graph keeps changing and updating constantly.
And then, is there any dump of twitter social graph data which I could use rather than making so many API c... | 0 | 1 | 2,436 |
0 | 786,758 | 0 | 0 | 0 | 0 | 1 | false | 6 | 2009-04-24T16:46:00.000 | 2 | 2 | 0 | Is there a Vector3 type in Python? | 786,691 | 0.197375 | python,vector | I don't believe there is anything standard (but I could be wrong, I don't keep up with python that closely).
It's very easy to implement though, and you may want to build on top of the numpy array as a container for it anyway, which gives you lots of good (and efficient) bits and pieces. | I quickly checked numPy but it looks like it's using arrays as vectors? I am looking for a proper Vector3 type that I can instance and work on. | 0 | 1 | 12,341 |
0 | 66,453,257 | 0 | 0 | 0 | 0 | 1 | false | 508 | 2009-05-17T12:02:00.000 | 12 | 12 | 0 | Read .mat files in Python | 874,461 | 1 | python,matlab,file-io,scipy,mat-file | There is a great library for this task called: pymatreader.
Just do as follows:
Install the package: pip install pymatreader
Import the relevant function of this package: from pymatreader import read_mat
Use the function to read the matlab struct: data = read_mat('matlab_struct.mat')
use data.keys() to locate where... | Is it possible to read binary MATLAB .mat files in Python?
I've seen that SciPy has alleged support for reading .mat files, but I'm unsuccessful with it. I installed SciPy version 0.7.0, and I can't find the loadmat() method. | 0 | 1 | 566,507 |
0 | 875,525 | 0 | 1 | 0 | 0 | 1 | false | 3 | 2009-05-17T19:00:00.000 | 2 | 5 | 0 | Simple data storing in Python | 875,228 | 0.07983 | python,file-io,csv,multidimensional-array,fileparsing | I'm looking for a simple solution using Python to store data as a flat file, such that each line is a string representation of an array that can be easily parsed.
Is the data only ever going to be parsed by Python programs? If not, then I'd avoid pickle et al (shelve and marshal) since they're very Python specific. JS... | I'm looking for a simple solution using Python to store data as a flat file, such that each line is a string representation of an array that can be easily parsed.
I'm sure python has library for doing such a task easily but so far all the approaches I have found seemed like it would have been sloppy to get it to work a... | 0 | 1 | 5,460 |
0 | 72,331,083 | 0 | 0 | 0 | 0 | 1 | false | 370 | 2009-05-24T00:08:00.000 | 0 | 21 | 0 | Saving a Numpy array as an image | 902,761 | 0 | python,image,numpy | I attach an simple routine to convert a npy to an image. Works 100% and it is a piece of cake!
from PIL import Image
import matplotlib
img = np.load('flair1_slice75.npy')
matplotlib.image.imsave("G1_flair_75.jpeg", img) | I have a matrix in the type of a Numpy array. How would I write it to disk it as an image? Any format works (png, jpeg, bmp...). One important constraint is that PIL is not present. | 0 | 1 | 767,103 |
0 | 968,351 | 0 | 0 | 0 | 0 | 2 | false | 1 | 2009-06-09T05:36:00.000 | 0 | 3 | 0 | How to isolate a single color in an image | 968,317 | 0 | python,image-processing,opencv,color-space | How about using a formular like r' = r-(g+b)? | I'm using the python OpenCV bindings and at the moment I try to isolate a colorrange. That means I want to filter out everything that is not reddish.
I tried to take only the red color channel but this includes the white spaces in the Image too.
What is a good way to do that? | 0 | 1 | 2,798 |
0 | 2,204,755 | 0 | 0 | 0 | 0 | 2 | false | 1 | 2009-06-09T05:36:00.000 | 1 | 3 | 0 | How to isolate a single color in an image | 968,317 | 0.066568 | python,image-processing,opencv,color-space | Use the HSV colorspace. Select pixels that have an H value in the range that you consider to contain "red," and an S value large enough that you do not consider it to be neutral, maroon, brown, or pink. You might also need to throw out pixels with low V's. The H dimension is a circle, and red is right where the circ... | I'm using the python OpenCV bindings and at the moment I try to isolate a colorrange. That means I want to filter out everything that is not reddish.
I tried to take only the red color channel but this includes the white spaces in the Image too.
What is a good way to do that? | 0 | 1 | 2,798 |
0 | 1,026,976 | 0 | 0 | 0 | 0 | 1 | false | 22 | 2009-06-22T12:26:00.000 | -11 | 6 | 0 | Algorithms for named entity recognition | 1,026,925 | -1 | php,python,extract,analysis,named-entity-recognition | I don't really know about NER, but judging from that example, you could make an algorithm that searched for capital letters in the words or something like that. For that I would recommend regex as the most easy to implement solution if you're thinking small.
Another option is to compare the texts with a database, wich ... | I would like to use named entity recognition (NER) to find adequate tags for texts in a database.
I know there is a Wikipedia article about this and lots of other pages describing NER, I would preferably hear something about this topic from you:
What experiences did you make with the various algorithms?
Which algorith... | 0 | 1 | 9,656 |
0 | 1,037,217 | 0 | 0 | 0 | 0 | 1 | false | 4 | 2009-06-24T08:30:00.000 | 1 | 1 | 0 | Simple Image Metrics with PIL | 1,037,090 | 0.197375 | python,python-imaging-library | I don't think there are methods that give you a metric exactly for what you want, but the methods that it has, like RMS, takes you a long way there. To do things with color, you can split the image into one layer per color, and get the RMS on each layer, which tells you some of the things you want to know. You can also... | I want to process uploaded photos with PIL and determine some "soft" image metrics like:
is the image contrastful or dull?
colorful or monochrome?
bright or dark?
is the image warm or cold (regarding light temperature)?
is there a dominant hue?
the metrics should be measured in a rating-style, e.g. colorful++++ for a... | 0 | 1 | 609 |
0 | 1,083,367 | 0 | 1 | 0 | 0 | 2 | false | 7 | 2009-07-05T02:49:00.000 | 2 | 4 | 0 | python csv question | 1,083,364 | 0.099668 | python,csv | test = csv.reader(c.split('\n')) | i'm just testing out the csv component in python, and i am having some trouble with it.
I have a fairly standard csv string, and the default options all seems to fit with my test, but the result shouldn't group 1, 2, 3, 4 in a row and 5, 6, 7, 8 in a row?
Thanks a lot for any enlightenment provided!
Python 2.6.2 (r26... | 0 | 1 | 850 |
0 | 1,083,376 | 0 | 1 | 0 | 0 | 2 | true | 7 | 2009-07-05T02:49:00.000 | 8 | 4 | 0 | python csv question | 1,083,364 | 1.2 | python,csv | csv.reader expects an iterable. You gave it "1, 2, 3, 4\n 5, 6, 7, 8\n"; iteration produces characters. Try giving it ["1, 2, 3, 4\n", "5, 6, 7, 8\n"] -- iteration will produce lines. | i'm just testing out the csv component in python, and i am having some trouble with it.
I have a fairly standard csv string, and the default options all seems to fit with my test, but the result shouldn't group 1, 2, 3, 4 in a row and 5, 6, 7, 8 in a row?
Thanks a lot for any enlightenment provided!
Python 2.6.2 (r26... | 0 | 1 | 850 |
0 | 1,095,296 | 0 | 0 | 1 | 0 | 2 | false | 51 | 2009-07-07T22:55:00.000 | 4 | 7 | 0 | Matrix from Python to MATLAB | 1,095,265 | 0.113791 | python,matlab,file-io,import,matrix | You could write the matrix in Python to a CSV file and read it in MATLAB using csvread. | I'm working with Python and MATLAB right now and I have a 2D array in Python that I need to write to a file and then be able to read it into MATLAB as a matrix. Any ideas on how to do this?
Thanks! | 0 | 1 | 69,405 |
0 | 7,737,622 | 0 | 0 | 1 | 0 | 2 | false | 51 | 2009-07-07T22:55:00.000 | 5 | 7 | 0 | Matrix from Python to MATLAB | 1,095,265 | 0.141893 | python,matlab,file-io,import,matrix | I would probably use numpy.savetxt('yourfile.mat',yourarray) in Python
and then yourarray = load('yourfile.mat') in MATLAB. | I'm working with Python and MATLAB right now and I have a 2D array in Python that I need to write to a file and then be able to read it into MATLAB as a matrix. Any ideas on how to do this?
Thanks! | 0 | 1 | 69,405 |
0 | 9,515,347 | 0 | 0 | 0 | 0 | 1 | false | 38 | 2009-07-26T21:43:00.000 | 0 | 9 | 0 | How to solve the "Mastermind" guessing game? | 1,185,634 | 0 | python,algorithm | To work out the "worst" case, instead of using entropic I am looking to the partition that has the maximum number of elements, then select the try that is a minimum for this maximum => This will give me the minimum number of remaining possibility when I am not lucky (which happens in the worst case).
This always solve ... | How would you create an algorithm to solve the following puzzle, "Mastermind"?
Your opponent has chosen four different colours from a set of six (yellow, blue, green, red, orange, purple). You must guess which they have chosen, and in what order. After each guess, your opponent tells you how many (but not which) of the... | 0 | 1 | 37,167 |
0 | 1,832,314 | 0 | 0 | 1 | 0 | 3 | false | 12 | 2009-07-28T02:43:00.000 | 2 | 7 | 0 | Hierarchical Bayes for R or Python | 1,191,689 | 0.057081 | python,r,statistics | I apply hierarchical Bayes models in R in combination with JAGS (Linux) or sometimes WinBUGS (Windows, or Wine). Check out the book of Andrew Gelman, as referred to above. | Hierarchical Bayes models are commonly used in Marketing, Political Science, and Econometrics. Yet, the only package I know of is bayesm, which is really a companion to a book (Bayesian Statistics and Marketing, by Rossi, et al.) Am I missing something? Is there a software package for R or Python doing the job out ther... | 0 | 1 | 8,690 |
0 | 55,978,470 | 0 | 0 | 1 | 0 | 3 | false | 12 | 2009-07-28T02:43:00.000 | 0 | 7 | 0 | Hierarchical Bayes for R or Python | 1,191,689 | 0 | python,r,statistics | This answer comes almost ten years late, but it will hopefully help someone in the future.
The brms package in R is a very good option for Bayesian hierarchical/multilevel models, using a syntax very similar to the lme4 package.
The brms package uses the probabilistic programming language Stan in the back to do the inf... | Hierarchical Bayes models are commonly used in Marketing, Political Science, and Econometrics. Yet, the only package I know of is bayesm, which is really a companion to a book (Bayesian Statistics and Marketing, by Rossi, et al.) Am I missing something? Is there a software package for R or Python doing the job out ther... | 0 | 1 | 8,690 |
0 | 1,197,766 | 0 | 0 | 1 | 0 | 3 | false | 12 | 2009-07-28T02:43:00.000 | 0 | 7 | 0 | Hierarchical Bayes for R or Python | 1,191,689 | 0 | python,r,statistics | The lme4 package, which estimates hierarchical models using frequentist methods, has a function called mcmcsamp that allows you to sample from the posterior distribution of the model using MCMC. This currently works only for linear models, quite unfortunately. | Hierarchical Bayes models are commonly used in Marketing, Political Science, and Econometrics. Yet, the only package I know of is bayesm, which is really a companion to a book (Bayesian Statistics and Marketing, by Rossi, et al.) Am I missing something? Is there a software package for R or Python doing the job out ther... | 0 | 1 | 8,690 |
0 | 1,199,371 | 0 | 1 | 0 | 0 | 2 | false | 2 | 2009-07-29T10:44:00.000 | 0 | 6 | 0 | Whats the best way of putting tabular data into python? | 1,199,350 | 0 | python,file,csv | Probably either a dict of list or a list of dict. Personally, I'd go with the former. So, parse the heading row of the CSV to get a dict from column heading to column index. Then when you're reading through each row, work out what index you're at, grab the column heading, and then append to the end of the list for that... | I have a CSV file which I am processing and putting the processed data into a text file.
The entire data that goes into the text file is one big table(comma separated instead of space). My problem is How do I remember the column into which a piece of data goes in the text file?
For eg. Assume there is a column called '... | 0 | 1 | 798 |
0 | 1,199,409 | 0 | 1 | 0 | 0 | 2 | false | 2 | 2009-07-29T10:44:00.000 | 1 | 6 | 0 | Whats the best way of putting tabular data into python? | 1,199,350 | 0.033321 | python,file,csv | Is SQLite an option for you? I know that you have CSV input and output. However, you can import all the data into the SQLite database. Then do all the necessary processing with the power of SQL. Then you can export the results as CSV. | I have a CSV file which I am processing and putting the processed data into a text file.
The entire data that goes into the text file is one big table(comma separated instead of space). My problem is How do I remember the column into which a piece of data goes in the text file?
For eg. Assume there is a column called '... | 0 | 1 | 798 |
0 | 1,208,039 | 0 | 0 | 0 | 0 | 1 | true | 22 | 2009-07-29T17:24:00.000 | 20 | 2 | 0 | Adding a field to a structured numpy array | 1,201,817 | 1.2 | python,numpy | If you're using numpy 1.3, there's also numpy.lib.recfunctions.append_fields().
For many installations, you'll need to import numpy.lib.recfunctions to access this. import numpy will not allow one to see the numpy.lib.recfunctions | What is the cleanest way to add a field to a structured numpy array? Can it be done destructively, or is it necessary to create a new array and copy over the existing fields? Are the contents of each field stored contiguously in memory so that such copying can be done efficiently? | 0 | 1 | 9,033 |
0 | 1,205,509 | 0 | 0 | 0 | 0 | 4 | true | 3 | 2009-07-30T09:22:00.000 | 3 | 4 | 0 | Neural net input/output | 1,205,449 | 1.2 | python,neural-network | You have to encode your input and your output to something that can be represented by the neural network units. ( for example 1 for "x has a certain property p" -1 for "x doesn't have the property p" if your units' range is in [-1, 1])
The way you encode your input and the way you decode your output depends on what you... | Can anyone explain to me how to do more complex data sets like team stats, weather, dice, complex number types
i understand all the math and how everything works i just dont know how to input more complex data, and then how to read the data it spits out
if someone could provide examples in python that would be a big ... | 0 | 1 | 671 |
0 | 20,683,280 | 0 | 0 | 0 | 0 | 4 | false | 3 | 2009-07-30T09:22:00.000 | 0 | 4 | 0 | Neural net input/output | 1,205,449 | 0 | python,neural-network | You have to add the number of units for input and output you need for the problem. If the unknown function to approximate depends on n parameter, you will have n input units. The number of output units depends on the nature of the funcion. For real functions with n real parameters you will have one output unit.
Some pr... | Can anyone explain to me how to do more complex data sets like team stats, weather, dice, complex number types
i understand all the math and how everything works i just dont know how to input more complex data, and then how to read the data it spits out
if someone could provide examples in python that would be a big ... | 0 | 1 | 671 |
0 | 1,207,505 | 0 | 0 | 0 | 0 | 4 | false | 3 | 2009-07-30T09:22:00.000 | 2 | 4 | 0 | Neural net input/output | 1,205,449 | 0.099668 | python,neural-network | Your features must be decomposed into parts that can be represented as real numbers. The magic of a Neural Net is it's a black box, the correct associations will be made (with internal weights) during the training
Inputs
Choose as few features as are needed to accurately describe the situation, then decompose each int... | Can anyone explain to me how to do more complex data sets like team stats, weather, dice, complex number types
i understand all the math and how everything works i just dont know how to input more complex data, and then how to read the data it spits out
if someone could provide examples in python that would be a big ... | 0 | 1 | 671 |
0 | 1,206,597 | 0 | 0 | 0 | 0 | 4 | false | 3 | 2009-07-30T09:22:00.000 | 0 | 4 | 0 | Neural net input/output | 1,205,449 | 0 | python,neural-network | More complex data usually means adding more neurons in the input and output layers.
You can feed each "field" of your register, properly encoded as a real value (normalized, etc.) to each input neuron, or maybe you can even decompose even further into bit fields, assigning saturated inputs of 1 or 0 to the neurons... f... | Can anyone explain to me how to do more complex data sets like team stats, weather, dice, complex number types
i understand all the math and how everything works i just dont know how to input more complex data, and then how to read the data it spits out
if someone could provide examples in python that would be a big ... | 0 | 1 | 671 |
0 | 1,226,509 | 0 | 0 | 0 | 0 | 1 | true | 2 | 2009-08-03T12:42:00.000 | 1 | 2 | 0 | Convolution of two functions in Python | 1,222,147 | 1.2 | python,convolution | Yes, SciPy/Numpy is mostly concerned about arrays.
If you can tolerate an approximate solution, and your functions only operate over a range of value (not infinite) you can fill an array with the values and convolve the arrays.
If you want something more "correct" calculus-wise you would probably need a powerful solver... | I will have to implement a convolution of two functions in Python, but SciPy/Numpy appear to have functions only for the convolution of two arrays.
Before I try to implement this by using the the regular integration expression of convolution, I would like to ask if someone knows of an already available module that perf... | 0 | 1 | 8,768 |
0 | 1,241,784 | 0 | 0 | 0 | 1 | 3 | false | 0 | 2009-08-06T21:58:00.000 | 0 | 4 | 0 | Store data series in file or database if I want to do row level math operations? | 1,241,758 | 0 | python,database,database-design,file-io | Are you likely to need all rows in order or will you want only specific known rows?
If you need to read all the data there isn't much advantage to having it in a database.
edit: If the code fits in memory then a simple CSV is fine. Plain text data formats are always easier to deal with than opaque ones if you can use t... | I'm developing an app that handle sets of financial series data (input as csv or open document), one set could be say 10's x 1000's up to double precision numbers (Simplifying, but thats what matters).
I plan to do operations on that data (eg. sum, difference, averages etc.) as well including generation of say another ... | 0 | 1 | 581 |
0 | 1,241,787 | 0 | 0 | 0 | 1 | 3 | false | 0 | 2009-08-06T21:58:00.000 | 0 | 4 | 0 | Store data series in file or database if I want to do row level math operations? | 1,241,758 | 0 | python,database,database-design,file-io | What matters most if all data will fit simultaneously into memory. From the size that you give, it seems that this is easily the case (a few megabytes at worst).
If so, I would discourage using a relational database, and do all operations directly in Python. Depending on what other processing you need, I would probably... | I'm developing an app that handle sets of financial series data (input as csv or open document), one set could be say 10's x 1000's up to double precision numbers (Simplifying, but thats what matters).
I plan to do operations on that data (eg. sum, difference, averages etc.) as well including generation of say another ... | 0 | 1 | 581 |
0 | 1,245,169 | 0 | 0 | 0 | 1 | 3 | true | 0 | 2009-08-06T21:58:00.000 | 2 | 4 | 0 | Store data series in file or database if I want to do row level math operations? | 1,241,758 | 1.2 | python,database,database-design,file-io | "I plan to do operations on that data (eg. sum, difference, averages etc.) as well including generation of say another column based on computations on the input."
This is the standard use case for a data warehouse star-schema design. Buy Kimball's The Data Warehouse Toolkit. Read (and understand) the star schema befo... | I'm developing an app that handle sets of financial series data (input as csv or open document), one set could be say 10's x 1000's up to double precision numbers (Simplifying, but thats what matters).
I plan to do operations on that data (eg. sum, difference, averages etc.) as well including generation of say another ... | 0 | 1 | 581 |
0 | 1,319,790 | 0 | 1 | 0 | 0 | 1 | false | 36 | 2009-08-23T22:33:00.000 | 4 | 10 | 0 | Key-ordered dict in Python | 1,319,763 | 0.07983 | python,data-structures,collections,dictionary | An ordered tree is usually better for this cases, but random access is going to be log(n). You should keep into account also insertion and removal costs... | I am looking for a solid implementation of an ordered associative array, that is, an ordered dictionary. I want the ordering in terms of keys, not of insertion order.
More precisely, I am looking for a space-efficent implementation of a int-to-float (or string-to-float for another use case) mapping structure for which... | 0 | 1 | 12,867 |
0 | 1,372,627 | 0 | 1 | 0 | 0 | 2 | false | 1 | 2009-09-03T10:02:00.000 | 1 | 4 | 0 | Algorithm to filter a set of all phrases containing in other phrase | 1,372,531 | 0.049958 | c#,java,c++,python,algorithm | You could build an index which maps words to phrases and do something like:
let matched = set of all phrases
for each word in the searched phrase
let wordMatch = all phrases containing the current word
let matched = intersection of matched and wordMatch
After this, matched would contain all phrases matching a... | Given a set of phrases, i would like to filter the set of all phrases that contain any of the other phrases. Contained here means that if a phrase contains all the words of another phrase it should be filtered out. Order of the words within the phrase does not matter.
What i have so far is this:
Sort the set by the nu... | 0 | 1 | 709 |
0 | 1,372,585 | 0 | 1 | 0 | 0 | 2 | false | 1 | 2009-09-03T10:02:00.000 | 0 | 4 | 0 | Algorithm to filter a set of all phrases containing in other phrase | 1,372,531 | 0 | c#,java,c++,python,algorithm | sort phrases by their contents, i.e., 'Z A' -> 'A Z', then eliminating phrases is easy going from shortest to longer ones. | Given a set of phrases, i would like to filter the set of all phrases that contain any of the other phrases. Contained here means that if a phrase contains all the words of another phrase it should be filtered out. Order of the words within the phrase does not matter.
What i have so far is this:
Sort the set by the nu... | 0 | 1 | 709 |
0 | 11,086,822 | 0 | 0 | 0 | 0 | 1 | false | 11 | 2009-09-04T03:44:00.000 | 4 | 4 | 0 | How do you deal with missing data using numpy/scipy? | 1,377,130 | 0.197375 | python,numpy,data-analysis | If you are willing to consider a library, pandas (http://pandas.pydata.org/) is a library built on top of numpy which amongst many other things provides:
Intelligent data alignment and integrated handling of missing data: gain automatic label-based alignment in computations and easily manipulate messy data into an ord... | One of the things I deal with most in data cleaning is missing values. R deals with this well using its "NA" missing data label. In python, it appears that I'll have to deal with masked arrays which seem to be a major pain to set up and don't seem to be well documented. Any suggestions on making this process easier in ... | 0 | 1 | 10,010 |
0 | 14,591,411 | 0 | 1 | 0 | 0 | 1 | false | 32 | 2009-09-09T17:57:00.000 | 0 | 3 | 0 | Python with matplotlib - drawing multiple figures in parallel | 1,401,102 | 0 | python,matplotlib,figures | The best way to show multiple figures is use matplotlib or pylab. (for windows)
with matplotlib you can prepare the figures and then when you finish the process with them you can show with the comand "matplotlib.show()" and all figures should be shown.
(on linux) you don´t have problems adding changes to figures becaus... | I have functions that contribute to small parts of a figure generation. I'm trying to use these functions to generate multiple figures? So something like this:
work with Figure 1
do something else
work with Figure 2
do something else
work with Figure 1
do something else
work with Figure 2
If anyone could help, that'd... | 0 | 1 | 43,360 |
0 | 1,418,321 | 0 | 1 | 1 | 0 | 3 | false | 2 | 2009-09-13T17:15:00.000 | 3 | 5 | 0 | Which is more pythonic for array removal? | 1,418,266 | 0.119427 | python | Speed depends on the ratio of hits to misses. To be pythonic choose the clearer method.
Personally I think way#1 is clearer (It takes less lines to have an 'if' block rather than an exception block and also uses less brain space). It will also be faster when there are more hits than misses (an exception is more expensi... | I'm removing an item from an array if it exists.
Two ways I can think of to do this
Way #1
# x array, r item to remove
if r in x :
x.remove( r )
Way #2
try :
x.remove( r )
except :
pass
Timing it shows the try/except way can be faster
(some times i'm getting:)
1.16225508968e-06
8.80804972547e-07
1.143141965... | 0 | 1 | 267 |
0 | 1,418,275 | 0 | 1 | 1 | 0 | 3 | false | 2 | 2009-09-13T17:15:00.000 | 2 | 5 | 0 | Which is more pythonic for array removal? | 1,418,266 | 0.07983 | python | The try/except way | I'm removing an item from an array if it exists.
Two ways I can think of to do this
Way #1
# x array, r item to remove
if r in x :
x.remove( r )
Way #2
try :
x.remove( r )
except :
pass
Timing it shows the try/except way can be faster
(some times i'm getting:)
1.16225508968e-06
8.80804972547e-07
1.143141965... | 0 | 1 | 267 |
0 | 1,418,310 | 0 | 1 | 1 | 0 | 3 | true | 2 | 2009-09-13T17:15:00.000 | 6 | 5 | 0 | Which is more pythonic for array removal? | 1,418,266 | 1.2 | python | I've always gone with the first method. if in reads far more clearly than exception handling does. | I'm removing an item from an array if it exists.
Two ways I can think of to do this
Way #1
# x array, r item to remove
if r in x :
x.remove( r )
Way #2
try :
x.remove( r )
except :
pass
Timing it shows the try/except way can be faster
(some times i'm getting:)
1.16225508968e-06
8.80804972547e-07
1.143141965... | 0 | 1 | 267 |
0 | 1,425,181 | 0 | 1 | 0 | 0 | 2 | false | 1 | 2009-09-15T04:48:00.000 | 1 | 4 | 0 | Symmetrically adressable matrix | 1,425,162 | 0.049958 | python,data-structures,matrix | You only need to store the lower triangle of the matrix. Typically this is done with one n(n+1)/2 length list. You'll need to overload the __getitem__ method to interpret what the entry means. | I'm looking to create a 2d matrix of integers with symmetric addressing ( i.e. matrix[2,3] and matrix[3,2] will return the same value ) in python. The integers will have addition and subtraction done on them, and be used for logical comparisons. My initial idea was to create the integer objects up front and try to fill... | 0 | 1 | 247 |
0 | 1,425,305 | 0 | 1 | 0 | 0 | 2 | false | 1 | 2009-09-15T04:48:00.000 | 2 | 4 | 0 | Symmetrically adressable matrix | 1,425,162 | 0.099668 | python,data-structures,matrix | You're probably better off using a full square numpy matrix. Yes, it wastes half the memory storing redundant values, but rolling your own symmetric matrix in Python will waste even more memory and CPU by storing and processing the integers as Python objects. | I'm looking to create a 2d matrix of integers with symmetric addressing ( i.e. matrix[2,3] and matrix[3,2] will return the same value ) in python. The integers will have addition and subtraction done on them, and be used for logical comparisons. My initial idea was to create the integer objects up front and try to fill... | 0 | 1 | 247 |
0 | 1,436,482 | 0 | 1 | 0 | 0 | 2 | false | 2 | 2009-09-17T02:18:00.000 | 2 | 6 | 0 | long-index arrays in python | 1,436,411 | 0.066568 | python | 10B booleans (1.25MB of memory, assuming Python is sane)
I think you have your arithmetic wrong -- stored supercompactly, 10B booleans would be 1.25 GIGA, _not__ MEGA, bytes.
A list takes at least 4 bytes per item, so you'd need 40GB to do it the way you want.
You can store an array (see the array module in the standa... | I'm attempting to shorten the memory footprint of 10B sequential integers by referencing them as indexes in a boolean array. In other words, I need to create an array of 10,000,000,000 elements, but that's well into the "Long" range. When I try to reference an array index greater than sys.maxint the array blows up:
x ... | 0 | 1 | 4,919 |
0 | 1,436,547 | 0 | 1 | 0 | 0 | 2 | false | 2 | 2009-09-17T02:18:00.000 | 3 | 6 | 0 | long-index arrays in python | 1,436,411 | 0.099668 | python | A dense bit vector is plausible but it won't be optimal unless you know you won't have more than about 10**10 elements, all clustered near each other, with a reasonably randomized distribution. If you have a different distribution, then a different structure will be better.
For instance, if you know that in that ran... | I'm attempting to shorten the memory footprint of 10B sequential integers by referencing them as indexes in a boolean array. In other words, I need to create an array of 10,000,000,000 elements, but that's well into the "Long" range. When I try to reference an array index greater than sys.maxint the array blows up:
x ... | 0 | 1 | 4,919 |
0 | 1,436,981 | 0 | 1 | 0 | 0 | 1 | false | 40 | 2009-09-17T06:07:00.000 | 9 | 3 | 0 | Python sort() method on list vs builtin sorted() function | 1,436,962 | 1 | python,sorting | Well, the .sort() method of lists sorts the list in place, while sorted() creates a new list. So if you have a large list, part of your performance difference will be due to copying.
Still, an order of magnitude difference seems larger than I'd expect. Perhaps list.sort() has some special-cased optimization that sort... | I know that __builtin__ sorted() function works on any iterable. But can someone explain this huge (10x) performance difference between anylist.sort() vs sorted(anylist) ? Also, please point out if I am doing anything wrong with way this is measured.
"""
Example Output:
$ python list_sort_timeit.py
Using sort method... | 0 | 1 | 63,711 |
0 | 1,448,617 | 0 | 0 | 0 | 0 | 1 | false | 0 | 2009-09-19T13:47:00.000 | 0 | 2 | 0 | Colour map in ipython | 1,448,582 | 0 | ironpython | Well i can\t quite get exactly what are you looking for, whole solution or maybe you've got problem with colors, if that second thing below you got some ideas
The most simple solution would be to create 14-elements array with color that you write from hand with help of some graphic software and than simply fetch elemen... | I am trying to plot some data in ipy.
The data consists of three variables alpha,beta and delta. The alpha and beta values are the coordinates of the data points that I wish to plot using a hammer projection. I want to scale the colour of the markers according to the delta values, preferably in a rainbow scale colormap... | 0 | 1 | 279 |
0 | 1,480,450 | 0 | 1 | 0 | 0 | 2 | true | 13 | 2009-09-26T04:23:00.000 | 7 | 4 | 0 | Most used Python module for video processing? | 1,480,431 | 1.2 | python,image-processing,video-processing | Do you mean opencv can't connect to your webcam or can't read video files recorded by it?
Have you tried saving the video in an other format?
OpenCV is probably the best supported python image processing tool | I need to:
Open a video file
Iterate over the frames of the file as images
Do some analysis in this image frame of the video
Draw in this image of the video
Create a new video with these changes
OpenCV isn't working for my webcam, but python-gst is working. Is this possible using python-gst?
Thank you! | 0 | 1 | 12,979 |
0 | 1,497,418 | 0 | 1 | 0 | 0 | 2 | false | 13 | 2009-09-26T04:23:00.000 | 0 | 4 | 0 | Most used Python module for video processing? | 1,480,431 | 0 | python,image-processing,video-processing | Just build a C/C++ wrapper for your webcam and then use SWIG or SIP to access these functions from Python. Then use OpenCV in Python that's the best open sourced computer vision library in the wild.
If you worry for performance and you work under Linux, you could download free versions of Intel Performance Primitives (... | I need to:
Open a video file
Iterate over the frames of the file as images
Do some analysis in this image frame of the video
Draw in this image of the video
Create a new video with these changes
OpenCV isn't working for my webcam, but python-gst is working. Is this possible using python-gst?
Thank you! | 0 | 1 | 12,979 |
0 | 1,506,741 | 0 | 0 | 0 | 0 | 1 | false | 4 | 2009-10-01T21:37:00.000 | 3 | 3 | 0 | Matplotlib square boxplot | 1,506,647 | 0.197375 | python,matplotlib,boxplot | Try axis('equal'). It's been a while since I worked with matplotlib, but I seem to remember typing that command a lot. | I have a plot of two boxplots in the same figure. For style reasons, the axis should have the same length, so that the graphic box is square. I tried to use the set_aspect method, but the axes are too different because of their range
and the result is terrible.
Is it possible to have 1:1 axes even if they do not have t... | 0 | 1 | 8,361 |
0 | 1,517,357 | 0 | 1 | 0 | 0 | 1 | false | 128 | 2009-10-04T20:48:00.000 | 10 | 3 | 0 | About Python's built in sort() method | 1,517,347 | 1 | python,algorithm,sorting,python-internals | In early python-versions, the sort function implemented a modified version of quicksort.
However, it was deemed unstable and as of 2.3 they switched to using an adaptive mergesort algorithm. | What algorithm is the built in sort() method in Python using? Is it possible to have a look at the code for that method? | 0 | 1 | 71,971 |
0 | 53,898,417 | 0 | 0 | 0 | 0 | 2 | false | 340 | 2009-10-05T13:56:00.000 | 0 | 17 | 0 | How do I check which version of NumPy I'm using? | 1,520,234 | 0 | python,numpy,version | It is good to know the version of numpy you run, but strictly speaking if you just need to have specific version on your system you can write like this:
pip install numpy==1.14.3 and this will install the version you need and uninstall other versions of numpy. | How can I check which version of NumPy I'm using? | 0 | 1 | 514,245 |
0 | 46,330,631 | 0 | 0 | 0 | 0 | 2 | false | 340 | 2009-10-05T13:56:00.000 | 11 | 17 | 0 | How do I check which version of NumPy I'm using? | 1,520,234 | 1 | python,numpy,version | You can try this:
pip show numpy | How can I check which version of NumPy I'm using? | 0 | 1 | 514,245 |
0 | 1,534,340 | 0 | 0 | 0 | 0 | 1 | false | 11 | 2009-10-07T11:08:00.000 | 1 | 4 | 0 | Incrementally building a numpy array and measuring memory usage | 1,530,960 | 0.049958 | python,numpy,memory-management | On possible option is to do a single pass through the file first to count the number of rows, without loading them.
The other option is to double your table size each time, which has two benefits:
You will only re-alloc memory log(n) times where n is the number of rows.
You only need 50% more ram than your largest tab... | I have a series of large text files (up to 1 gig) that are output from an experiment that need to be analysed in Python. They would be best loaded into a 2D numpy array, which presents the first question:
As the number of rows is unknown at the beginning of the loading, how can
a very large numpy array be most efficie... | 0 | 1 | 6,464 |
0 | 1,545,672 | 0 | 0 | 0 | 0 | 1 | false | 49 | 2009-10-09T19:16:00.000 | 0 | 8 | 0 | Python k-means algorithm | 1,545,606 | 0 | python,algorithm,cluster-analysis,k-means | You can also use GDAL, which has many many functions to work with spatial data. | I am looking for Python implementation of k-means algorithm with examples to cluster and cache my database of coordinates. | 0 | 1 | 89,635 |
0 | 1,553,126 | 0 | 0 | 0 | 0 | 1 | true | 2 | 2009-10-12T07:06:00.000 | 5 | 4 | 0 | Generate random directories/files given number of files and depth | 1,553,114 | 1.2 | python,algorithm | Why not download some real open source repos and use those?
Have you thought about what goes into the files? is that random data too? | I'd like to profile some VCS software, and to do so I want to generate a set of random files, in randomly arranged directories. I'm writing the script in Python, but my question is briefly: how do I generate a random directory tree with an average number of sub-directories per directory and some broad distribution of f... | 0 | 1 | 3,603 |
0 | 1,592,512 | 0 | 1 | 0 | 0 | 2 | false | 2 | 2009-10-19T23:51:00.000 | 1 | 3 | 0 | How to make all combinations of the elements in an array? | 1,591,762 | 0.066568 | python | You haven't made it completely clear what you need. It sounds like itertools should have what you need. Perhaps what you wish is an itertools.combinations of the itertools.product of the lists in your big list.
@fortran: you can't have a set of sets. You can have a set of frozensets, but depending on what it really me... | I have a list. It contains x lists, each with y elements.
I want to pair each element with all the other elements, just once, (a,b = b,a)
EDIT: this has been criticized as being too vague.So I'll describe the history.
My function produces random equations and using genetic techniques, mutates and crossbreeds them, sele... | 0 | 1 | 598 |
0 | 1,591,802 | 0 | 1 | 0 | 0 | 2 | false | 2 | 2009-10-19T23:51:00.000 | 0 | 3 | 0 | How to make all combinations of the elements in an array? | 1,591,762 | 0 | python | First of all, please don't refer to this as an "array". You are using a list of lists. In Python, an array is a different type of data structure, provided by the array module.
Also, your application sounds suspiciously like a matrix. If you are really doing matrix manipulations, you should investigate the Numpy packag... | I have a list. It contains x lists, each with y elements.
I want to pair each element with all the other elements, just once, (a,b = b,a)
EDIT: this has been criticized as being too vague.So I'll describe the history.
My function produces random equations and using genetic techniques, mutates and crossbreeds them, sele... | 0 | 1 | 598 |
0 | 1,594,704 | 0 | 0 | 0 | 1 | 5 | false | 3 | 2009-10-20T13:27:00.000 | 3 | 7 | 0 | How should I optimize this filesystem I/O bound program? | 1,594,604 | 0.085505 | python,performance,optimization,file-io | If you are I/O bound, the best way I have found to optimize is to read or write the entire file into/out of memory at once, then operate out of RAM from there on.
With extensive testing I found that my runtime eded up bound not by the amount of data I read from/wrote to disk, but by the number of I/O operations I used ... | I have a python program that does something like this:
Read a row from a csv file.
Do some transformations on it.
Break it up into the actual rows as they would be written to the database.
Write those rows to individual csv files.
Go back to step 1 unless the file has been totally read.
Run SQL*Loader and load those f... | 0 | 1 | 2,504 |
0 | 1,595,358 | 0 | 0 | 0 | 1 | 5 | false | 3 | 2009-10-20T13:27:00.000 | 1 | 7 | 0 | How should I optimize this filesystem I/O bound program? | 1,594,604 | 0.028564 | python,performance,optimization,file-io | Use buffered writes for step 4.
Write a simple function that simply appends the output onto a string, checks the string length, and only writes when you have enough which should be some multiple of 4k bytes. I would say start with 32k buffers and time it.
You would have one buffer per file, so that most "writes" won't ... | I have a python program that does something like this:
Read a row from a csv file.
Do some transformations on it.
Break it up into the actual rows as they would be written to the database.
Write those rows to individual csv files.
Go back to step 1 unless the file has been totally read.
Run SQL*Loader and load those f... | 0 | 1 | 2,504 |
0 | 1,595,626 | 0 | 0 | 0 | 1 | 5 | true | 3 | 2009-10-20T13:27:00.000 | 3 | 7 | 0 | How should I optimize this filesystem I/O bound program? | 1,594,604 | 1.2 | python,performance,optimization,file-io | Python already does IO buffering and the OS should handle both prefetching the input file and delaying writes until it needs the RAM for something else or just gets uneasy about having dirty data in RAM for too long. Unless you force the OS to write them immediately, like closing the file after each write or opening t... | I have a python program that does something like this:
Read a row from a csv file.
Do some transformations on it.
Break it up into the actual rows as they would be written to the database.
Write those rows to individual csv files.
Go back to step 1 unless the file has been totally read.
Run SQL*Loader and load those f... | 0 | 1 | 2,504 |
0 | 1,597,062 | 0 | 0 | 0 | 1 | 5 | false | 3 | 2009-10-20T13:27:00.000 | 2 | 7 | 0 | How should I optimize this filesystem I/O bound program? | 1,594,604 | 0.057081 | python,performance,optimization,file-io | Can you use a ramdisk for step 4? Low millions sounds doable if the rows are less than a couple of kB or so. | I have a python program that does something like this:
Read a row from a csv file.
Do some transformations on it.
Break it up into the actual rows as they would be written to the database.
Write those rows to individual csv files.
Go back to step 1 unless the file has been totally read.
Run SQL*Loader and load those f... | 0 | 1 | 2,504 |
0 | 1,597,281 | 0 | 0 | 0 | 1 | 5 | false | 3 | 2009-10-20T13:27:00.000 | 1 | 7 | 0 | How should I optimize this filesystem I/O bound program? | 1,594,604 | 0.028564 | python,performance,optimization,file-io | Isn't it possible to collect a few thousand rows in ram, then go directly to the database server and execute them?
This would remove the save to and load from the disk that step 4 entails.
If the database server is transactional, this is also a safe way to do it - just have the database begin before your first row and... | I have a python program that does something like this:
Read a row from a csv file.
Do some transformations on it.
Break it up into the actual rows as they would be written to the database.
Write those rows to individual csv files.
Go back to step 1 unless the file has been totally read.
Run SQL*Loader and load those f... | 0 | 1 | 2,504 |
0 | 1,654,390 | 0 | 1 | 0 | 0 | 4 | false | 4 | 2009-10-31T09:38:00.000 | 7 | 5 | 0 | If pickling was interrupted, will unpickling necessarily always fail? - Python | 1,653,897 | 1 | python | Contra the other answers offered, I believe that we can make a strong argument about the recoverability of a pickle. That answer is: "Yes, an incomplete pickle always leads to an exception."
Why are we able to do this? Because the "pickle" format is in fact a small stack-based language. In a stack-based language you wr... | Suppose my attempt to write a pickle object out to disk is incomplete due to a crash. Will an attempt to unpickle the object always lead to an exception or is it possible that the fragment that was written out may be interpreted as valid pickle and the error go unnoticed? | 0 | 1 | 1,351 |
0 | 1,654,321 | 0 | 1 | 0 | 0 | 4 | false | 4 | 2009-10-31T09:38:00.000 | 1 | 5 | 0 | If pickling was interrupted, will unpickling necessarily always fail? - Python | 1,653,897 | 0.039979 | python | I doubt you could make a claim that it will always lead to an exception. Pickles are actually programs written in a specialized stack language. The internal details of pickles change from version to version, and new pickle protocols are added occasionally. The state of the pickle after a crash, and the resulting eff... | Suppose my attempt to write a pickle object out to disk is incomplete due to a crash. Will an attempt to unpickle the object always lead to an exception or is it possible that the fragment that was written out may be interpreted as valid pickle and the error go unnoticed? | 0 | 1 | 1,351 |
0 | 1,654,503 | 0 | 1 | 0 | 0 | 4 | false | 4 | 2009-10-31T09:38:00.000 | 1 | 5 | 0 | If pickling was interrupted, will unpickling necessarily always fail? - Python | 1,653,897 | 0.039979 | python | To be sure that you have a "complete" pickle file, you need to pickle three things.
Pickle a header of some kind that claims how many objects and what the end-of-file flag will look like. A tuple of an integer and the EOF string, for example.
Pickle the objects you actually care about. The count is given by the head... | Suppose my attempt to write a pickle object out to disk is incomplete due to a crash. Will an attempt to unpickle the object always lead to an exception or is it possible that the fragment that was written out may be interpreted as valid pickle and the error go unnoticed? | 0 | 1 | 1,351 |
0 | 1,654,329 | 0 | 1 | 0 | 0 | 4 | false | 4 | 2009-10-31T09:38:00.000 | 2 | 5 | 0 | If pickling was interrupted, will unpickling necessarily always fail? - Python | 1,653,897 | 0.07983 | python | Pickling an object returns an str object, or writes an str object to a file ... it doesn't modify the original object. If a "crash" (exception) happens inside a pickling call, the result won't be returned to the caller, so you don't have anything that you could try to unpickle. Besides, why would you want to unpickle s... | Suppose my attempt to write a pickle object out to disk is incomplete due to a crash. Will an attempt to unpickle the object always lead to an exception or is it possible that the fragment that was written out may be interpreted as valid pickle and the error go unnoticed? | 0 | 1 | 1,351 |
0 | 1,662,207 | 0 | 0 | 0 | 0 | 2 | true | 11 | 2009-11-02T14:01:00.000 | 13 | 2 | 0 | matplotlib for R user? | 1,661,479 | 1.2 | python,r,matplotlib,scipy,data-visualization | This is a tough one to answer.
I recently switched some of my graphing workload from R to matplotlib. In my humble opinion, I find matplotlib's graphs to be prettier (better default colors, they look crisper and more modern). I also think matplotlib renders PNGs a whole lot better.
The real motivation for me though... | I regularly make figures (the exploratory data analysis type) in R. I also program in Python and was wondering if there are features or concepts in matplotlib that would be worth learning. For instance, I am quite happy with R - but its image() function will produce large files with pixelated output, whereas Matlab's e... | 0 | 1 | 10,755 |
0 | 1,662,225 | 0 | 0 | 0 | 0 | 2 | false | 11 | 2009-11-02T14:01:00.000 | 4 | 2 | 0 | matplotlib for R user? | 1,661,479 | 0.379949 | python,r,matplotlib,scipy,data-visualization | I think that the largest advantage is that matplotlib is based on Python, which you say you already know. So, this is one language less to learn. Just spend the time mastering Python, and you'll benefit both directly for the plotting task at hand and indirectly for your other Python needs.
Besides, IMHO Python is an o... | I regularly make figures (the exploratory data analysis type) in R. I also program in Python and was wondering if there are features or concepts in matplotlib that would be worth learning. For instance, I am quite happy with R - but its image() function will produce large files with pixelated output, whereas Matlab's e... | 0 | 1 | 10,755 |
0 | 1,687,712 | 0 | 0 | 0 | 0 | 1 | true | 9 | 2009-11-06T13:10:00.000 | 9 | 2 | 0 | What is the default chunker for NLTK toolkit in Python? | 1,687,510 | 1.2 | python,nlp,nltk,chunking | You can get out of the box named entity chunking with the nltk.ne_chunk() method. It takes a list of POS tagged tuples:
nltk.ne_chunk([('Barack', 'NNP'), ('Obama', 'NNP'), ('lives', 'NNS'), ('in', 'IN'), ('Washington', 'NNP')])
results in:
Tree('S', [Tree('PERSON', [('Barack', 'NNP')]), Tree('ORGANIZATION', [('Obama',... | I am using their default POS tagging and default tokenization..and it seems sufficient. I'd like their default chunker too.
I am reading the NLTK toolkit book, but it does not seem like they have a default chunker? | 0 | 1 | 4,560 |
0 | 58,050,062 | 0 | 0 | 0 | 0 | 4 | false | 6 | 2009-11-08T10:29:00.000 | 0 | 5 | 0 | Does WordNet have "levels"? (NLP) | 1,695,971 | 0 | python,text,nlp,words,wordnet | sorry, may I ask which tool could judge "difficulty level" of sentences?
I wish to find out "similar difficulty level" of sentences for user to read. | For example...
Chicken is an animal.
Burrito is a food.
WordNet allows you to do "is-a"...the hiearchy feature.
However, how do I know when to stop travelling up the tree? I want a LEVEL.
That is consistent.
For example, if presented with a bunch of words, I want wordNet to categorize all of them, but at a certain leve... | 0 | 1 | 2,585 |
Subsets and Splits
Python & ML Questions
Retrieves a subset of entries tagged with both 'python' and 'machine-learning', providing a basic filtered view of relevant data.
Python & ML Questions
Retrieves all records tagged with both 'python' and 'machine-learning', providing a basic filtered subset of the dataset.