Charles R Harris | 9 Feb 16:29
Picon

Cython question

Hi All,

Does anyone know how to make Cython emit a C macro? I would like to be able to

#define NO_DEPRECATED_API

and can do so by including a header file or futzing with the generator script, but I was wondering if there was an easy way to do it in Cython.

Chuck

_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion <at> scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion
Eirik Gjerløw | 9 Feb 12:32
Picon
Picon
Gravatar

Numpy array slicing

Hello,

(also sent to Scipy-User, sorry for duplicates).

This is (I think) a rather basic question about numpy slicing. I have 
the following code:

In [29]: a.shape
Out[29]: (3, 4, 12288, 2)

In [30]: mask.shape
Out[30]: (3, 12288)

In [31]: mask.dtype
Out[31]: dtype('bool')

In [32]: sum(mask[0])
Out[32]: 12285

In [33]: a[[0] + [slice(None)] + [mask[0]] + [slice(None)]].shape
Out[33]: (12285, 4, 2)

My question is: Why is not the final shape (4, 12285, 2) instead of 
(12285, 4, 2)?

Eirik Gjerløw
teomat | 9 Feb 08:31
Picon
Gravatar

numpy.arange() error?


Hi,

Am I wrong or the numpy.arange() function is not correct 100%?

Try to do this:

In [7]: len(np.arange(3.1, 4.9, 0.1))
Out[7]: 18

In [8]: len(np.arange(8.1, 9.9, 0.1))
Out[8]: 19

I would expect the same result for each command.

All the best

--

-- 
View this message in context: http://old.nabble.com/numpy.arange%28%29-error--tp33277269p33277269.html
Sent from the Numpy-discussion mailing list archive at Nabble.com.
Debashish Saha | 8 Feb 19:18
Picon
Gravatar

how to insert some specific delay

how to insert some specific delay in python programming using numpy command.
John Salvatier | 8 Feb 18:10
Gravatar

just the date part of a datetime64[s]?


Hello, is there a good way to get just the date part of a datetime64? Frequently datetime datatypes have month(), date(), hour(), etc functions that pull out part of the datetime, but I didn't see those mentioned in the datetime64 docs. Casting to a 'D' dtype didn't work as I would have hoped:

In [30]: x= datetime64('2012-02-02 09:00:00', 's')

In [31]: x
Out[31]: numpy.datetime64('2012-02-02T09:00:00-0800')

In [32]: x.astype('datetime64[D]').astype('datetime64[s]')
Out[32]: numpy.datetime64('2012-02-01T16:00:00-0800')

What's the simplest way to do this? 

_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion <at> scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion
Stephanie Cooke | 8 Feb 17:32
Picon
Gravatar

hstack

Hello,

When I try to use the command hstack, I am given the error message
"TypeError: hstack() takes exactly 1 argument (2 given)". I have a 9X1
array (called array) that I would like to concatenate to a 9X2 matrix
(called matrix), and I try to do this by typing the command
hstack(array,matrix). I would appreciate any help in getting this to
work.

Thanks,

Stephanie
Gravatar

Logical indexing and higher-dimensional arrays.

Consider the following. Is this a bug?

Thanks,
- Jordi G. H.

-----------------------------------------------
#!/usr/bin/python

import numpy as np

x = np.reshape(np.random.uniform(size=2*3*4), [2,3,4])

idx = np.array([False, True, False, True])
y = x[0,:,:];

## Why is this transposed?
print x[0, :, idx].T == y[:, idx]

## This doesn't happen with non-boolean indexing
print x[0, :, 1:3] == y[:, 1:3]
John Salvatier | 6 Feb 21:40
Gravatar

datetime64 format parameter?

Hello, 


Is there a way to specify a format for the datetime64 constructor? The constructor doesn't have a doc. I have dates in a file with the format "MM/dd/YY". datetime64 used to be able to parse these in 1.6.1 but the dev version throws an error.

Cheers,
John
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion <at> scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion
Debashish Saha | 6 Feb 20:21
Picon
Gravatar

(no subject)

basic difference between the commands:
import numpy as np
from numpy import *
Picon
Picon
Favicon

Structure of polynomial module

Hi all,

I noticed the following docstring on ``np.polynomial.polyval``:

In [116]: np.polynomial.polyval?
File:       /home/stefan/src/numpy/numpy/lib/utils.py
Definition: np.polynomial.polyval(*args, **kwds)
Docstring:
`polyval` is deprecated!
Please import polyval from numpy.polynomial.polynomial

I guess we don't expect users to do "from numpy.polynomial.polynomial
import polyval, Polynomial", so what is the suggested API for getting
hold of the polynomial functions?  Also, why is
numpy.polynomial.polynomial.polyfit different from numpy.polyfit?

Regards
Stéfan
Picon
Picon
Favicon

avoiding loops when downsampling arrays

Hello,

I have to write a code to downsample an array in a specific way, and I am hoping that
somebody can tell me how to do this without the nested do-loops.  Here is the problem
statement:  Segment a (MXN) array into 4x4 squares and set a flag if any of the pixels
in that 4x4 square meet a certain condition.

Here is the code that I want to rewrite avoiding loops:

shape_out = (data_in.shape[0]/4, data_in.shape[1]/4)
found = numpy.zeros(shape_out).astype(numpy.bool)

for i in xrange(0, shape_out[0]):
	for j in xrange(0, shape_out[1]):

		excerpt = data_in[i*4:(i+1)*4, j*4:(j+1)*4]
		mask = numpy.where( (excerpt >= t1) & (excerpt <= t2), True, False)
		if (numpy.any(mask)):
			found[i,j] = True

Thank you for any hints and education!

Catherine

Gmane