Tagged Questions
5
votes
2answers
25 views
Numpy size of data type
In numpy, I can get the size (in bytes) of a particular data type by:
datatype(...).itemsize
or:
datatype(...).nbytes
e.g.:
np.float32(5).itemsize #4
np.float32(5).nbytes #4
I have 2 ...
2
votes
5answers
39 views
Find unique rows in numpy.array
I need to find unique rows in a numpy.array.
For example:
>>> a # I have
array([[1, 1, 1, 0, 0, 0],
[0, 1, 1, 1, 0, 0],
[0, 1, 1, 1, 0, 0],
[1, 1, 1, 0, 0, 0],
...
2
votes
1answer
28 views
Error when trying to apply log method to pandas data frame column in Python
So, I am very new to Python and Pandas (and programming in general), but am having trouble with a seemingly simple function. So I created the following dataframe using data pulled with a SQL query (if ...
1
vote
1answer
34 views
Python: precision failure in computing acute angle
We use the following code for computing acute angle between two lines.
def AcuteAngle2(line1,line2):
''':: line(x1,y1,x2,y2)'''
u = (line1[2]-line1[0], line1[3]-line1[1])
v = ...
1
vote
0answers
36 views
creating and manipulating 3d arrays
I am (very) new to python, previously a Matlab user.
I try to create code to load times series into the rows of a matrix [serie1, 2, 3, etc.] and then manipulate those time series into a loop (see ...
2
votes
1answer
46 views
Creating sublist from a give list of items
I would say first that the following question is not for homework purpose even because i've finish software engineer a few months ago. Anyway today I was working and one friend ask to me this strange ...
2
votes
1answer
40 views
Difference between Python float and numpy float32
What is the difference between the built in float and numpy.float32?
Example
a = 58682.7578125
print type(a)
print a
print type(numpy.float32(a))
print numpy.float32(a)
Output:
<type ...
1
vote
0answers
42 views
Constructing high resolution images in Python
Say I have some huge amount of data stored in an HDF5 data file (size: 20k x 20k, if not more) and I want to create an image from all of this data using Python. Obviously, this much data cannot be ...
1
vote
1answer
22 views
Populate predefined numpy array with arrays as columns
Something I can't figure out by reading the Python documentation and stackoverflow. Probably I'm thinking in the wrong direction..
Let's say I've a predefined 2D Numpy array as follow:
a = ...
2
votes
1answer
20 views
Grouping array to nested structure with numpy
Say I've got a numpy array like this (larger and with different number of repetitions per date):
data = np.array([ \
["2011-01-01", 24, 554, 66], \
["2011-01-01", 44, 524, 62], \
...
3
votes
2answers
62 views
binning a dataframe in pandas in Python
given the following dataframe in pandas:
import numpy as np
df = pandas.DataFrame({"a": np.random.random(100), "b": np.random.random(100), "id": np.arange(100)})
where id is an id for each point ...
4
votes
3answers
47 views
Numpy Convert String Representation of Boolean Array To Boolean Array
Is there a native numpy way to convert an array of string representations of booleans eg:
['True','False','True','False']
To an actual boolean array I can use for masking/indexing? I could do a for ...
3
votes
2answers
33 views
NumPy array, change the values that are NOT in a list of indices
I have a numpy array like:
a = np.arange(30)
I know that I can replace the values located at positions indices=[2,3,4] using for instance fancy indexing:
a[indices] = 999
But how to replace the ...
1
vote
2answers
56 views
numpy np.array versus np.matrix (performance)
often when working with numpy I find the distinction annoying - when I pull out a vector or a row from a matrix and then perform operations with np.arrays there are usually problems.
to reduce ...
5
votes
2answers
59 views
Can I trick numpy.histogram into behaving like numpy.bincount?
So, I have lists of words and I need to know how often each word appears on each list. Using ".count(word)" works, but it's too slow (each list has thousands of words and I have thousands of lists).
...