All Questions

Tagged with
158
votes
20answers
70k views

Find unique rows in numpy.array

I need to find unique rows in a numpy.array.For example:>>> a # I havearray([[1, 1, 1, 0, 0, 0],[0, 1, 1, 1, 0, 0],[0, 1, 1, 1, 0, 0],[1, 1, 1, 0, 0, 0],[...
106
votes
9answers
78k views

Using numpy to build an array of all combinations of two arrays

I'm trying to run over the parameters space of a 6 parameter function to study it's numerical behavior before trying to do anything complex with it so I'm searching for a efficient way to do this.My ...
9
votes
5answers
4k views

Find the row indexes of several values in a numpy array

I have an array X:X=np.array([[4, 2],[9, 3],[8, 5],[3, 3],[5, 6]])And I wish to find the index of the row of several values in ...
266
votes
12answers
200k views

Check if multiple strings exist in another string

How can I check if any of the strings in an array exists in another string?Like:a=['a', 'b', 'c']str="a123"if a in str:print "some of the strings found in str"else:print "no strings ...
280
votes
4answers
104k views

What are the differences between numpy arrays and matrices? Which one should I use?

What are the advantages and disadvantages of each?From what I've seen, either one can work as a replacement for the other if need be, so should I bother using both or should I stick to just one of ...
228
votes
9answers
198k views

Sorting arrays in NumPy by column

How can I sort an array in NumPy by the nth column?For example,a=array([[9, 2, 3],[4, 5, 6],[7, 0, 5]])I'd like to sort rows by the second column, such that I get back:...
132
votes
7answers
51k views

How is Python's List Implemented?

Is it a linked list, an array? I searched around and only found people guessing. My C knowledge isn't good enough to look at the source code.
382
votes
13answers
339k views

How to print the full NumPy array?

When I print a numpy array, I get a truncated representation, but I want the full array. Is there any way to do this?Examples:>>> numpy.arange(10000)array([ 0, 1, 2, ..., 9997, ...
106
votes
5answers
492k views

ValueError: setting an array element with a sequence

This Python code:import numpy as pdef firstfunction():UnFilteredDuringExSummaryOfMeansArray=[]MeanOutputHeader=['TestID','ConditionName','FilterType','RRMean','HRMean','...
96
votes
9answers
127k views

How Big can a Python Array Get?

In Python, how big can an array/list get? I need an array of about 12000 elements. Will I still be able to run array/list methods such as sorting, etc?
340
votes
13answers
448k views

Is there a NumPy function to return the first index of something in an array?

I know there is a method for a Python list to return the first index of something:>>> l=list([1, 2, 3])>>> l.index(2)1Is there something like that for NumPy arrays?
46
votes
6answers
21k views

Numpy `logical_or` for more than two arguments

Numpy's logical_or function takes no more than two arrays to compare. How can I find the union of more than two arrays? (The same question could be asked with regard to Numpy's logical_and and ...
306
votes
9answers
268k views

Python List vs. Array - when to use?

If you are creating a 1d array, you can implement it as a List, or else use the 'array' module in the standard library. I have always used Lists for 1d arrays.What is the reason or circumstance ...
131
votes
10answers
227k views

convert a string of bytes into an int (python)

How can I convert a string of bytes into an int in python? Say like this: 'y\xcc\xa6\xbb'I came up with a clever/stupid way of doing it:sum(ord(c) << (i * 8) for i, c in enumerate('y\xcc\...
83
votes
8answers
107k views

How to find list intersection?

a=[1,2,3,4,5]b=[1,3,5,6]c=a and bprint cactual output: [1,3,5,6]expected output: [1,3,5]How can we achieve a boolean AND operation (list intersection) on two lists?
108
votes
8answers
200k views

hexadecimal string to byte array in python

I have a long Hex string that represents a series of values of different types. I wish to convert this Hex String into a byte array so that I can shift each value out and convert it into its proper ...
19
votes
2answers
22k views

Computing the correlation coefficient between two multi-dimensional arrays

I have two arrays that have the shapes N X T and M X T. I'd like to compute the correlation coefficient across T between every possible pair of rows n and m (from N and M, respectively).What's the ...
66
votes
3answers
8k views

Why is numpy's einsum faster than numpy's built in functions?

Lets start with three arrays of dtype=np.double. Timings are performed on a intel CPU using numpy 1.7.1 compiled with icc and linked to intel's mkl. A AMD cpu with numpy 1.6.1 compiled with gcc ...
32
votes
2answers
31k views

Store different datatypes in one NumPy array?

I have two different arrays, one with strings and another with ints. I want to concatenate them, into one array where each column has the original datatype. My current solution for doing this (see ...
371
votes
9answers
383k views

Dump a NumPy array into a csv file

Is there a way to dump a NumPy array into a CSV file? I have a 2D NumPy array and need to dump it in human-readable format.
154
votes
14answers
167k views

numpy: most efficient frequency counts for unique values in an array

In numpy / scipy, is there an efficient way to get frequency counts for unique values in an array?Something along these lines:x=array( [1,1,1,2,2,2,5,25,1,1] )y=freq_count( x )print y>&...
91
votes
6answers
504k views

How to read a text file into a list or an array with Python

I am trying to read the lines of a text file into a list or array in python. I just need to be able to individually access any item in the list or array after it is created.The text file is ...
24
votes
2answers
7k views

Set partitions in Python

I have an array of [1,2,3]I want to make all the possible combinations using all elements of the array:Result:[[1], [2], [3]][[1,2], [3]][[1], [2,3]][[1,3], [2]][[1,2,3]]
32
votes
6answers
24k views

How to apply a disc shaped mask to a numpy array?

I have an array like this:>>> np.ones((8,8))array([[ 1., 1., 1., 1., 1., 1., 1., 1.],[ 1., 1., 1., 1., 1., 1., 1., 1.],[ 1., 1., 1., 1., 1., 1., 1., 1.]...
157
votes
4answers
209k views

Comparing two numpy arrays for equality, element-wise

What is the simplest way to compare two numpy arrays for equality (where equality is defined as: A=B iff for all indices i: A[i] ==B[i])?Simply using==gives me a boolean array:>>> ...
200
votes
11answers
462k views

Convert pandas dataframe to numpy array, preserving index

I am interested in knowing how to convert a pandas dataframe into a numpy array, including the index, and set the dtypes.dataframe:import numpy as npimport pandas as pdindex=[1, 2, 3, 4, 5, 6,...
113
votes
4answers
27k views

Understanding NumPy's einsum

I'm struggling to understand exactly how einsum works. I've looked at the documentation and a few examples, but it's not seeming to stick.Here's an example we went over in class:C=np.einsum("ij,...
117
votes
9answers
166k views

Numpy matrix to array

I am using numpy. I have a matrix with 1 column and N rows and I want to get an array from with N elements.For example, if i have M=matrix([[1], [2], [3], [4]]), I want to get A=array([1,2,3,4])....
16
votes
5answers
3k views

Convert Python sequence to NumPy array, filling missing values

The implicit conversion of a Python sequence of variable-length lists into a NumPy array cause the array to be of type object.v=[[1], [1, 2]]np.array(v)>>> array([[1], [1, 2]], dtype=...
124
votes
7answers
230k views

how does multiplication differ for NumPy Matrix vs Array classes?

The numpy docs recommend using array instead of matrix for working with matrices. However, unlike octave (which I was using till recently), * doesn't perform matrix multiplication, you need to use the ...

153050per page
angop.ao, elkhabar.com, noa.al, afghanpaper.com, bbc.com, time.com, cdc.gov, nih.gov, xnxx.com, github.com,