0

For example, I have a variable which point to a vector contains many elements in memory, I want to copy element in vector to a numpy array, what should I do except one by one copy? Thx

1
  • 3
    can you give a concrete code example? Commented Nov 14, 2012 at 15:56

2 Answers 2

1

I am assuming that your vector can be represented like that:-

import array

x = array('l', [1, 3, 10, 5, 6])   # an array using python's built-in array module

Casting it as a numpy array will then be:-

import numpy as np

y = np.array(x)
Sign up to request clarification or add additional context in comments.

Comments

0

If the data is packed in a buffer in native float format:

a = numpy.fromstring(buf, dtype=float, count=N)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.