473,405 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

array of array of float

i used C too much and haven't used Python for a while...

like in C, if we want an array of array of float, we use

float a[200][500];

now in Python, seems like we have to do something like

a = [ [ ] ] * 200

and then just use

a[1].append(12.34) etc

but it turns out that all 200 elements points to the same list...
and i have to use

a = [ ]
for i in range (0, 200):
a.append([ ])

is there a simpler way... i wonder...

Jul 9 '06 #1
6 3806
Su************@gmail.com wrote:
i used C too much and haven't used Python for a while...

like in C, if we want an array of array of float, we use

float a[200][500];

now in Python, seems like we have to do something like

a = [ [ ] ] * 200

and then just use

a[1].append(12.34) etc

but it turns out that all 200 elements points to the same list...
and i have to use

a = [ ]
for i in range (0, 200):
a.append([ ])

is there a simpler way... i wonder...
this is FAQ:

http://pyfaq.infogami.com/how-do-i-c...mensional-list

</F>

Jul 9 '06 #2
DH
Su************@gmail.com wrote:
i used C too much and haven't used Python for a while...

like in C, if we want an array of array of float, we use

float a[200][500];

now in Python, seems like we have to do something like

a = [ [ ] ] * 200

and then just use

a[1].append(12.34) etc

but it turns out that all 200 elements points to the same list...
and i have to use

a = [ ]
for i in range (0, 200):
a.append([ ])

is there a simpler way... i wonder...
Right, try the numpy module, and you can do:

from numpy import *
a = zeros((200,500), Float)

documentation:
http://numeric.scipy.org/numpydoc/nu...ml#pgfId-60291
download:
http://sourceforge.net/project/showf...kage_id=175103
main page:
http://numeric.scipy.org/
Jul 9 '06 #3
Su************@gmail.com schrieb:
i used C too much and haven't used Python for a while...

like in C, if we want an array of array of float, we use

float a[200][500];

now in Python, seems like we have to do something like

a = [ [ ] ] * 200

and then just use

a[1].append(12.34) etc

but it turns out that all 200 elements points to the same list...
and i have to use

a = [ ]
for i in range (0, 200):
a.append([ ])

is there a simpler way... i wonder...
a = [[] for in range(200)]
Jul 9 '06 #4
Schüle Daniel schrieb:
Su************@gmail.com schrieb:
>i used C too much and haven't used Python for a while...

like in C, if we want an array of array of float, we use

float a[200][500];

now in Python, seems like we have to do something like

a = [ [ ] ] * 200

and then just use

a[1].append(12.34) etc

but it turns out that all 200 elements points to the same list...
and i have to use

a = [ ]
for i in range (0, 200):
a.append([ ])

is there a simpler way... i wonder...

a = [[] for in range(200)]
correction :)

a = [[] for i in range(200)]
Jul 9 '06 #5
Use nested list comprehensions:

matrix = [[0.0 for x in xrange(n)] for y in xrange(m)]

This is similar to "float matrix[m][n]" in C.

All cells are independent of each other in doing this.

Jul 9 '06 #6
"Schüle Daniel" wrote:
a = [[] for in range(200)]

correction :)

a = [[] for i in range(200)]
the "*500" part still seems to be missing...

</F>

Jul 12 '06 #7

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

Similar topics

19
by: Steven T. Hatton | last post by:
I believe it is technically possible to return a pointer to the first element of an array. I can persuade the returned pointer to act like an array, with some qualifications. I'm specifically...
6
by: Vamsee | last post by:
I have a 4D array: float T; ( have to go atleast upto T if system supports) How to malloc() it? can you please give me a brief illustration because I haven't found any article dealing with...
15
by: fdunne2 | last post by:
The following C-code implements a simple FIR filter: //realtime filter demo #include <stdio.h> #include <stdlib.h> //function defination float rtFilter1(float *num, float *den, float...
11
by: Marc Pelletier | last post by:
Hello, I am having trouble implementing the following callback: CNCSError CECWCompressor::WriteReadLine(UINT32 nNextLine, void **ppInputArray) where ppInputArray is a 3 by x array. The...
3
by: Lars Grobe | last post by:
Hi, first hello, I am new to the list, and I guess my question will show that clearly. I want to use some vector operations (at the moment altivec) in existing code. It is a raytracing-based...
9
by: Gregory.A.Book | last post by:
I am interested in converting sets of 4 bytes to floats in C++. I have a library that reads image data and returns the data as an array of unsigned chars. The image data is stored as 4-byte floats....
5
by: xxx | last post by:
Hi all, i'm new in visual c++ and i'm having troubles converting types. Let me explain: i have an unmanaged c++ function that wants an float* parameter but i have an array<float>^, how i can covert...
29
by: Vasileios Zografos | last post by:
Hi everyone, I need to build a function to plug it in a program (that I didnt make or can change) that should be called something like this: float someFunction(float x) { ...
11
by: memeticvirus | last post by:
I have an array cli::array<float, 2and I would like to access a subset of it's values by compiling an array of pointers. But, it's not possible to create an array of type...
33
by: Adam Chapman | last post by:
Hi, Im trying to migrate from programming in Matlab over to C. Im trying to make a simple function to multiply one matrix by the other. I've realised that C can't determine the size of a 2d...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...

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.