samedi 27 juin 2015

Add string to a Numpy Array

I have a given list 'l' and given string 's', How can I combine them as shown in the required answer?

import numpy as np

l = [(1, 2),
     (3, 4),
     (5, 6)]

s = 'ax'

The required answer is:

ans = array([[ax, 1, 2],
             [ax, 3, 4],
             [ax, 5, 6]])

I tried as:

ans = np.column_stack([s, l])

wrong!

Aucun commentaire:

Enregistrer un commentaire