473,756 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Questions on migrating from Numeric/Scipy to Numpy

vj
I've tried to post this to the numpy google group but it seems to be
down. My migration seems to be going well. I currently have one issue
with using scipy_base.inse rt.
>>a = zeros(5)
mask = zeros(5)
mask[1] = 1
c = zeros(1)
c[0] = 100
numpy.insert( a, mask, c)
array([ 100., 0., 100., 100., 100., 0., 0., 0.,
0., 0.])
>>a
array([ 0., 0., 0., 0., 0.])
>>b
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 1], dtype=int8)
>>mask
array([ 0., 1., 0., 0., 0.])
>>c
array([ 100.])

I would have expected numpy.insert to update a so that the second
element in a would be 100.

Thanks,

VJ

Mar 14 '07 #1
7 1929
vj wrote:
I've tried to post this to the numpy google group but it seems to be
down.
It is just a redirection to the nu************* *@scipy.org list. If you just
tried in the past hour or so, I've discovered that our DNS appears to be down
right now.
My migration seems to be going well. I currently have one issue
with using scipy_base.inse rt.
>>>a = zeros(5)
mask = zeros(5)
mask[1] = 1
c = zeros(1)
c[0] = 100
numpy.insert (a, mask, c)
array([ 100., 0., 100., 100., 100., 0., 0., 0.,
0., 0.])
>>>a
array([ 0., 0., 0., 0., 0.])
>>>b
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 1], dtype=int8)
>>>mask
array([ 0., 1., 0., 0., 0.])
>>>c
array([ 100.])

I would have expected numpy.insert to update a so that the second
element in a would be 100.
No, that's not what insert() does. See the docstring:

In [1]: from numpy import *

In [2]: insert?
Type: function
Base Class: <type 'function'>
Namespace: Interactive
File:
/Library/Frameworks/Python.framewor k/Versions/2.5/lib/python2.5/site-packages/numpy-1.0.2.dev3569-py2.5-macosx-10.3-fat.egg/numpy/lib/function_base.p y
Definition: insert(arr, obj, values, axis=None)
Docstring:
Return a new array with values inserted along the given axis
before the given indices

If axis is None, then ravel the array first.

The obj argument can be an integer, a slice, or a sequence of
integers.

Example:
>>a = array([[1,2,3],
... [4,5,6],
... [7,8,9]])
>>insert(a, [1,2], [[4],[5]], axis=0)
array([[1, 2, 3],
[4, 4, 4],
[4, 5, 6],
[5, 5, 5],
[7, 8, 9]])
The behaviour that you seem to want would be accomplished with the following:

In [3]: a = zeros(5)

In [4]: mask = zeros(5, dtype=bool)

In [5]: mask[1] = True

In [6]: mask
Out[6]: array([False, True, False, False, False], dtype=bool)

In [7]: a[mask] = 100

In [8]: a
Out[8]: array([ 0., 100., 0., 0., 0.])
Note that the mask needs to be a bool array.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Mar 14 '07 #2
vj
It is just a redirection to the numpy-discuss...@scip y.org list. If you just
tried in the past hour or so, I've discovered that our DNS appears to be down
right now.
I tried registering the twice the last couple of days and never got an
email back.
No, that's not what insert() does. See the docstring:
Then this behavior is different from the scipy_base.inse rt
In [7]: a[mask] = 100
What I needed was

a[mask] = array_of_values

I just tried it and it works.

Thanks,

VJ

Mar 14 '07 #3
vj
Note that the mask needs to be a bool array.
>>mask = zeros(5)
mask = zeros(5, numpy.int8)
mask[1] = True
mask[2] = True
a = zeros(5)
a[mask] = [100, 200]
a
array([ 100., 100., 0., 0., 0.])

I found this strange. It should just give an error if you try to use a
mask array of non booleans. It's working great so far.

Thanks for all the hard work.

VJ

Mar 14 '07 #4
vj wrote:
>It is just a redirection to the numpy-discuss...@scip y.org list. If you just
tried in the past hour or so, I've discovered that our DNS appears to be down
right now.

I tried registering the twice the last couple of days and never got an
email back.
Hmm. Odd. I just tried to register and haven't gotten a confirmation email, yet,
either. I'll get our sysadmin on it.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Mar 14 '07 #5
vj wrote:
>Note that the mask needs to be a bool array.
>>>mask = zeros(5)
mask = zeros(5, numpy.int8)
mask[1] = True
mask[2] = True
a = zeros(5)
a[mask] = [100, 200]
a
array([ 100., 100., 0., 0., 0.])

I found this strange. It should just give an error if you try to use a
mask array of non booleans.
No, it simply does something different. Boolean arrays apply as a mask. Integer
arrays apply as indices into the array.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Mar 14 '07 #6
vj
What should I be using to replace Numeric/arrayobject.h:

numpy/arrayobject.h

or

numpy/oldnumeric.h

Thanks,

VJ

Mar 14 '07 #7
vj wrote:
What should I be using to replace Numeric/arrayobject.h:

numpy/arrayobject.h

or

numpy/oldnumeric.h
Replacing "numpy/oldnumeric.h" is the compatibility header. If you don't want to
convert your code to use the new APIs (and you might; it is much improved), then
that should be all that you need to do to get your old extension modules running
with numpy.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Mar 14 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
2011
by: J | last post by:
Hi I hope the title of this message indicates my question. I am looking for basic array functionality in Python and it turns out that there are all these packages which are somehow related. Some are allegedly discontinued but still seem to get updated. Could we start a discussion about which package will or may or should survive ?
0
1625
by: jantod | last post by:
I am trying to package my application with py2exe. Unfortunately it uses both scipy/numpy and numarray so I'm having to jump through a lot of hoops to get it going. I'm getting problems packaging an app that uses only scipy. See below. Thanks! Janto ===setup.py=== from distutils.core import setup
10
2243
by: Bryan | last post by:
hi, what is the difference among numeric, numpy and numarray? i'm going to start using matplotlib soon and i'm not sure which one i should use. this page says, "Numarray is a re-implementation of an older Python array module called Numeric" http://www.stsci.edu/resources/software_hardware/numarray
2
3947
by: robert | last post by:
I'm using latest numpy & scipy. What is this problem ? : RuntimeError: module compiled against version 1000002 of C-API but this version of numpy is 1000009 Traceback (most recent call last): File "<interactive input>", line 1, in ? File "C:\PYTHON23\Lib\site-packages\scipy\stats\__init__.py", line 7, in ? from stats import * File "C:\PYTHON23\Lib\site-packages\scipy\stats\stats.py", line 191, in ? import scipy.special as special File...
18
22401
by: robert | last post by:
Is there a ready made function in numpy/scipy to compute the correlation y=mx+o of an X and Y fast: m, m-err, o, o-err, r-coef,r-coef-err ? Or a formula to to compute the 3 error ranges? -robert PS: numpy.corrcoef computes only the bare coeff:
4
2818
by: HYRY | last post by:
Why the exec time of test(readdata()) and test(randomdata()) of following program is different? my test file 150Hz10dB.wav has 2586024 samples, so I set randomdata function to return a list with 2586024 samples. the exec result is: 2586024 <type 'list'> 10.8603842736 2586024
5
4130
by: auditory | last post by:
I am a newbie here I am trying to read "space separated floating point data" from file I read about csv module by searching this group, but I couldn't read space separated values with csv. (which may be matter of course..) I also read about numpy.fromfile(file, sep=' ') which i can use. but on my machine(ubuntu linux) numpy is unknown module,
5
1286
by: Erik Johnson | last post by:
I am just starting to explore doing some scientific type data analysis using Python, and am a little confused by the different incarnations of modules (e.g., try Google("Python numeric"). There is SciPy, NumPy, NumArray, Numeric... I know some of these are related and some are separate, some are oudated, etc. but can someone sort of give a general run-down in layman's terms of what's what, what's used for what, what depends on what, and...
4
3076
by: Talbot Katz | last post by:
Greetings Pythoners! I hope you'll indulge an ignorant outsider. I work at a financial software firm, and the tool I currently use for my research is R, a software environment for statistical computing and graphics. R is designed with matrix manipulation in mind, and it's very easy to do regression and time series modeling, and to plot the results and test hypotheses. The kinds of functionality we rely on the most are standard and...
0
9271
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10031
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9838
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9708
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8709
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7242
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3354
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.