Hi,
is it possible to append data to or remove data from numpy arrays like
Python lists? I have some code where I currently use lists and often
do things like
a.append(elem)
a += b
del a[:-n]
I am thinking of changing to numpy arrays but it seems I cannot modify
numpy arrays like
Seb wrote:
> Is there an easier way to write a numpy array with a regular structure?
> For example, an array with [0, 1] along the diagnal of one of the array
> dimensions, and zero elsewhere:
>
> zz = np.array([[[0, 1], [0, 0], [0, 0]],
>[[0, 0], [0, 1], [0, 0]],
>
Hello,
Is there an easier way to write a numpy array with a regular structure?
For example, an array with [0, 1] along the diagnal of one of the array
dimensions, and zero elsewhere:
zz = np.array([[[0, 1], [0, 0], [0, 0]],
[[0, 0], [0, 1], [0, 0]],
[[0, 0], [0, 0],
Some common ways to handle the boundary condition:
1. Generate clamped indices, test for validity and substitute invalid
entries with an "identity" element. E.g.
ijk = np.mgrid[:a,:b,:c]
i,j,k = ijk
i0,j0,k0 = np.maximum(0,ijk-1)
i1,j1,k1 = np.minimum(np.array(a,b,c).T-1,ijk+1)
n1 = (i>
Heli wrote:
> I have a 3d numpy array containing true/false values for each i,j,k. The
> size of the array is a*b*c.
>
> for each cell with indices i,j,k; I will need to check all its neighbours
> and calculate the number of neighbour cells with true values.
>
> A cell with index i,j,k has the f
Hi,
I have a 3d numpy array containing true/false values for each i,j,k. The size
of the array is a*b*c.
for each cell with indices i,j,k; I will need to check all its neighbours and
calculate the number of neighbour cells with true values.
A cell with index i,j,k has the following neighbou
As you said, this did the trick.
sortedVal=np.array(val[ind]).reshape((xcoord.size,ycoord.size,zcoord.size))
Only val[ind] instead of val[ind,:] as val is 1D.
Thanks Oscar,
--
https://mail.python.org/mailman/listinfo/python-list
Thanks Oscar,
In my case this did the trick.
sortedVal=np.array(val[ind]).reshape((xcoord.size,ycoord.size,zcoord.size))
--
https://mail.python.org/mailman/listinfo/python-list
On 7 April 2016 at 15:31, Heli wrote:
>
> Thanks a lot Oscar,
>
> The lexsort you suggested was the way to go.
Glad to hear it.
> import h5py
> import numpy as np
> f=np.loadtxt(inputFile,delimiter=None)
> xcoord=np.sort(np.unique(f[:,0]))
> ycoord=np.sort(np.unique(f[:,1]))
> zcoord=np.sort(np.
Thanks a lot Oscar,
The lexsort you suggested was the way to go.
import h5py
import numpy as np
f=np.loadtxt(inputFile,delimiter=None)
xcoord=np.sort(np.unique(f[:,0]))
ycoord=np.sort(np.unique(f[:,1]))
zcoord=np.sort(np.unique(f[:,2]))
x=f[:,0]
y=f[:,1]
z=f[:,2]
val=f[:,3]
ind = np.lexsort(
On 6 April 2016 at 17:26, Heli wrote:
>
> Thanks for your replies. I have a question in regard with my previous
> question. I have a file that contains x,y,z and a value for that coordinate
> on each line. Here I am giving an example of the file using a numpy array
> called f.
>
> f=np.array([[
Thanks for your replies. I have a question in regard with my previous question.
I have a file that contains x,y,z and a value for that coordinate on each line.
Here I am giving an example of the file using a numpy array called f.
f=np.array([[1,1,1,1],
[1,1,2,2],
[1,1,3
> What you want is called *transposing* the array:
>
> http://docs.scipy.org/doc/numpy/reference/generated/numpy.transpose.html
>
> That should be a sufficiently fast operation.
Transposing itself is fast, as it just swaps the strides and dimensions
without touching the data (i.e. it returns a n
On 23 March 2016 10:06:56 GMT+00:00, Heli wrote:
>Hi,
>
>I have a 2D numpy array like this:
>
>[[1,2,3,4],
> [1,2,3,4],
> [1,2,3,4]
> [1,2,3,4]]
>
>Is there any fast way to convert this array to
>
>[[1,1,1,1],
> [2,2,2,2]
> [3,3,3,3]
> [4,4,4,4]]
Use the transpose() method:
http://docs.scipy
On Wednesday, March 23, 2016 at 11:07:27 AM UTC+1, Heli wrote:
> Hi,
>
> I have a 2D numpy array like this:
>
> [[1,2,3,4],
> [1,2,3,4],
> [1,2,3,4]
> [1,2,3,4]]
>
> Is there any fast way to convert this array to
>
> [[1,1,1,1],
> [2,2,2,2]
> [3,3,3,3]
> [4,4,4,4]]
>
> In general I wo
On Wed, Mar 23, 2016 at 9:06 PM, Heli wrote:
> I have a 2D numpy array like this:
>
> [[1,2,3,4],
> [1,2,3,4],
> [1,2,3,4]
> [1,2,3,4]]
>
> Is there any fast way to convert this array to
>
> [[1,1,1,1],
> [2,2,2,2]
> [3,3,3,3]
> [4,4,4,4]]
What you want is called *transposing* the array:
h
On 03/23/16 at 03:06am, Heli wrote:
> I have a 2D numpy array like this:
>
> [[1,2,3,4],
> [1,2,3,4],
> [1,2,3,4]
> [1,2,3,4]]
>
> Is there any fast way to convert this array to
>
> [[1,1,1,1],
> [2,2,2,2]
> [3,3,3,3]
> [4,4,4,4]]
You don't mean just transposing your original array, as
On Wed, 23 Mar 2016 09:06 pm, Heli wrote:
> Hi,
>
> I have a 2D numpy array like this:
>
> [[1,2,3,4],
> [1,2,3,4],
> [1,2,3,4]
> [1,2,3,4]]
>
> Is there any fast way to convert this array to
>
> [[1,1,1,1],
> [2,2,2,2]
> [3,3,3,3]
> [4,4,4,4]]
Mathematically, this is called the "tran
Hi,
I have a 2D numpy array like this:
[[1,2,3,4],
[1,2,3,4],
[1,2,3,4]
[1,2,3,4]]
Is there any fast way to convert this array to
[[1,1,1,1],
[2,2,2,2]
[3,3,3,3]
[4,4,4,4]]
In general I would need to retrieve every nth element of the interior arrays in
to single arrays. I know I can
; convenient to work with than lists of lists. What are the advantages and
> disadvantages of storing the symbols [A,B] and dates
> [2014-01-01,2014-01-02] as lists vs. NumPy arrays?
If you don't mind the numpy dependency I can't see any disadvantages.
You might also have a look at
nvenient to work with than lists of lists. What are the advantages and
> disadvantages of storing the symbols [A,B] and dates
> [2014-01-01,2014-01-02] as lists vs. NumPy arrays?
You could also use a dictionary of either lists or tuples or even NumPy
arrays keyed on the date.
$ python
Python
storing the symbols [A,B] and dates [2014-01-01,2014-01-02] as
lists vs. NumPy arrays?
--
https://mail.python.org/mailman/listinfo/python-list
On Thu, 02 May 2013 02:10:11 -0700, Ana Dionísio wrote:
> Hello! I have several numpy arrays in my script and i want to add them.
> For example:
>
> a=[1,2,3,4,5]
> b=[1,1,1,1,1]
> c=[1,0,1,0,1]
These are not numpy arrays, they are lists of ints. Based on the error
Ana Dionísio wrote:
> Hello! I have several numpy arrays in my script and i want to add them. For
> example:
> a=[1,2,3,4,5]
> b=[1,1,1,1,1]
> c=[1,0,1,0,1]
> for i in range(5):
> d[i]=a[i]+b[i]+c[i]
> print d
> [3,3,5,5,7]
> I did it like that
Hello! I have several numpy arrays in my script and i want to add them. For
example:
a=[1,2,3,4,5]
b=[1,1,1,1,1]
c=[1,0,1,0,1]
for i in range(5):
d[i]=a[i]+b[i]+c[i]
print d
[3,3,5,5,7]
I did it like that but I get an error: "TypeError: unsupported operand type(s)
for +: '
in indices:
... print inds, af[inds], af[inds].sum()
...
[1 7 8] [2 8 9] 19
[0 1] [1 2] 3
[8 4] [9 5] 14
Knowing the most efficient way depends on a number of things. The first
would be whether or not the operation you're describing is repeated. If,
for example, you keep doing this for the sa
Thanks guys
I implemented a numpy array with fancy indices and got rid of the list and
the loops. The time to do the mapping improved ~10x. As a matter of fact,
the number of elements in array A to be summed and mapped was different for
each element in B (which was the reason I was using lists). B
On 25 June 2012 08:24, Stefan Behnel wrote:
> Saurabh Kabra, 25.06.2012 05:37:
> > I have written a script to map a 2D numpy array(A) onto another array(B)
> of
> > different dimension. more than one element (of array A) are summed and
> > mapped to each element of array B. To achieve this I cre
Saurabh Kabra, 25.06.2012 05:37:
> I have written a script to map a 2D numpy array(A) onto another array(B) of
> different dimension. more than one element (of array A) are summed and
> mapped to each element of array B. To achieve this I create a list where I
> store the index of array A to be ma
I have written a script to map a 2D numpy array(A) onto another array(B) of
different dimension. more than one element (of array A) are summed and
mapped to each element of array B. To achieve this I create a list where I
store the index of array A to be mapped to array B. The list is the
dimensio
; some numpy float arrays (obtained from np.fromfile and np.cov
> > > functions) and would like to convert them to simple python arrays.
> > > I was wondering which is the best way to do that? Is there any
> > > function to do that?
>
> > HiJavier,
> > Si
; functions) and would like to convert them to simple python arrays.
> > I was wondering which is the best way to do that? Is there any
> > function to do that?
>
> Hi Javier,
> Since you are new to Python I'll ask whether you want to convert Numpy
> arrays to Pytho
s the best way to do that? Is there any
function to do that?
Hi Javier,
Since you are new to Python I'll ask whether you want to convert Numpy
arrays to Python arrays (as you stated) or Python lists. Python lists
are used very frequently; Python arrays see very little use outside of
numpy
Dear all,
I'm new to python and have been working with the numpy package. I have
some numpy float arrays (obtained from np.fromfile and np.cov
functions) and would like to convert them to simple python arrays.
I was wondering which is the best way to do that? Is there any
function to do that?
Bes
Robert Kern schrieb:
Probably, you need to use zeros(..., dtype=uint8). When you use
dtype=int, that will result in dtype=int arrays. I suspect that
matplotlib is then interpreting that to mean that you want it to treat
the input as scalar data (which it will pass through a colormap) rather
th
On 2009-07-09 12:34, Sebastian Schabe wrote:
Hello everybody,
I want to concatenate 2 numpy array which in fact are RGB images:
def concat_images(im1,im2):
rows1 = im1.shape[0]
rows2 = im2.shape[0]
if rows1 < rows2:
im1 = concatenate((im1,zeros((rows2-rows1,im1.shape[1],3), int)), axis=0)
elif
Hello everybody,
I want to concatenate 2 numpy array which in fact are RGB images:
def concat_images(im1,im2):
rows1 = im1.shape[0]
rows2 = im2.shape[0]
if rows1 < rows2:
im1 = concatenate((im1,zeros((rows2-rows1,im1.shape[1],3), int)),
axis=0)
elif rows1 > rows2:
im2 = concat
Almar Klein wrote:
Basically, we want a[i][j] == a[i,j]. Since there is no literal
syntax for numpy arrays, we need to be able to convert from a
sequence of sequences to an array. The indexing needs to correspond
between the two.
Thanks for the reply. I guess that explains
> Basically, we want a[i][j] == a[i,j]. Since there is no literal syntax for
> numpy arrays, we need to be able to convert from a sequence of sequences to
> an array. The indexing needs to correspond between the two.
>
Thanks for the reply. I guess that explains the *why*...
Ado
Almar Klein wrote:
Hi,
I was wondering...
Say we have a np.ndarray A of two dimensions (a grayscale image for
example). If we want to access x:2, y:3, we have to do A[3,2]. Why is
the order of x and y reversed?
Because images are stored by rows, not by columns. So column 3, row 2,
is row
are often used this way. (In Matlab the data is actually stored
last-dimensions-first too.)
Basically, we want a[i][j] == a[i,j]. Since there is no literal syntax for numpy
arrays, we need to be able to convert from a sequence of sequences to an array.
The indexing needs to correspond between
Hi,
I was wondering...
Say we have a np.ndarray A of two dimensions (a grayscale image for
example). If we want to access x:2, y:3, we have to do A[3,2]. Why is
the order of x and y reversed?
This is reversed in Matlab too, because Matlab is a matrix package and
matrix are often used this way. (I
sturlamolden wrote:
On Sep 10, 6:39 am, Travis Oliphant <[EMAIL PROTECTED]> wrote:
I wanted to point anybody interested to a blog post that describes a
useful pattern for having a NumPy array that points to the memory
created by a different memory manager than the standard one used by
NumPy.
On Sep 10, 6:39 am, Travis Oliphant <[EMAIL PROTECTED]> wrote:
> I wanted to point anybody interested to a blog post that describes a
> useful pattern for having a NumPy array that points to the memory
> created by a different memory manager than the standard one used by
> NumPy.
Here is somethi
I wanted to point anybody interested to a blog post that describes a
useful pattern for having a NumPy array that points to the memory
created by a different memory manager than the standard one used by
NumPy. The pattern shows how to create a NumPy array that points to
previously allocate
You will want to ask numpy questions on the numpy mailing list:
http://www.scipy.org/Mailing_Lists
I need a little more time to mull on your problem to give you an actual answer,
but I hope I can do that over there instead of here.
--
Robert Kern
"I have come to believe that the whole worl
Hi,
I'm writing a quick script to import a fits (astronomy) image that has
very low values for each pixel. Mostly on the order of 10^-9. I have
written a python script that attempts to take low values and put them
in integer format. I basically do this by taking the mean of the 1000
lowest pixel v
Martin Manns wrote:
> On Sun, 13 Jan 2008 16:03:16 -0600
> Robert Kern <[EMAIL PROTECTED]> wrote:
>
>> Martin Manns wrote:
>>> Hi,
>>>
>>> I have created a class that wraps a numpy array of custom objects. I
>>> would like to be able to slice respective objects (without copying
>>> the array if po
On Sun, 13 Jan 2008 16:03:16 -0600
Robert Kern <[EMAIL PROTECTED]> wrote:
> Martin Manns wrote:
> > Hi,
> >
> > I have created a class that wraps a numpy array of custom objects. I
> > would like to be able to slice respective objects (without copying
> > the array if possible).
> >
> > I have b
Martin Manns wrote:
> Hi,
>
> I have created a class that wraps a numpy array of custom objects. I
> would like to be able to slice respective objects (without copying the
> array if possible).
>
> I have browsed the doc and found some hints at __getitem__. However, I
> still do not grasp how to
Hi,
I have created a class that wraps a numpy array of custom objects. I
would like to be able to slice respective objects (without copying the
array if possible).
I have browsed the doc and found some hints at __getitem__. However, I
still do not grasp how to do it. How do I implement __getitem
Rolf Wester wrote:
> Hi,
>
> I want to concatenate two numpy arrays with shape (n1,n2) and (n1,n3)
> into a single array with shape (n1,n2+n3). I guess there is an elegant
> way to do this but I couldn't figure it out. So any help is very much
> appreciated.
>
Suppo
Hi,
I want to concatenate two numpy arrays with shape (n1,n2) and (n1,n3)
into a single array with shape (n1,n2+n3). I guess there is an elegant
way to do this but I couldn't figure it out. So any help is very much
appreciated.
Regards
Rolf
--
http://mail.python.org/mailman/listinfo/p
I've been in contact with Travis O, and he said it was fixed in the
SVN.
thanks for the suggestions, I'll try them out now.
best
Sonja
Filip Wasilewski wrote:
> sonjaa wrote:
> > Hi
> >
> > last week I posted a problem with running out of memory when changing
&g
sonjaa wrote:
> Hi
>
> last week I posted a problem with running out of memory when changing
> values in NumPy arrays. Since then I have tried many different
> approaches and
> work-arounds but to no avail.
[...]
Based on the numpy-discussion this seems to be fixed in the SVN no
sonjaa wrote:
> Also, are there other python methods/extensions that can create
> multi-deminsional arrays?
if this example is typical for the code you're writing, you might as
well use nested Python lists:
def make_array(width, height, value):
out = []
for y in range(hei
sonjaa wrote:
> Hi
>
> last week I posted a problem with running out of memory when changing
> values in NumPy arrays. Since then I have tried many different
> approaches and
> work-arounds but to no avail.
>
> I was able to reduce the code (see below) to its smallest siz
Hi
last week I posted a problem with running out of memory when changing
values in NumPy arrays. Since then I have tried many different
approaches and
work-arounds but to no avail.
I was able to reduce the code (see below) to its smallest size and
still
have the problem, albeit at a slower rate
58 matches
Mail list logo