logo
down
shadow

How to change array layout?


How to change array layout?

By : Fahrur Rozi
Date : November 22 2020, 02:59 PM
wish helps you One approach with ndarray.transpose and np.concatenate -
code :
np.concatenate((a1[...,None].transpose(1,0,2),a2[...,None].transpose(1,0,2)),2)
np.concatenate((a1.T[...,None],a2.T[...,None]),2)
np.dstack((a1,a2)).transpose(1,0,2)
In [63]: a1 = np.random.rand(500,300)
    ...: a2 = np.random.rand(500,300)
    ...: 

In [64]: %timeit np.concatenate((a1[...,None].transpose(1,0,2),a2[...,None].transpose(1,0,2)),2)
100 loops, best of 3: 3.02 ms per loop

In [65]: %timeit np.concatenate((a1.T[...,None],a2.T[...,None]),2)
100 loops, best of 3: 3.03 ms per loop

In [66]: %timeit np.dstack((a1,a2)).transpose(1,0,2)
100 loops, best of 3: 3.05 ms per loop

In [67]: a1 = np.random.rand(5000,3000)
    ...: a2 = np.random.rand(5000,3000)
    ...: 

In [68]: %timeit np.concatenate((a1[...,None].transpose(1,0,2),a2[...,None].transpose(1,0,2)),2)
1 loops, best of 3: 372 ms per loop

In [69]: %timeit np.concatenate((a1.T[...,None],a2.T[...,None]),2)
1 loops, best of 3: 373 ms per loop

In [70]: %timeit np.dstack((a1,a2)).transpose(1,0,2)
1 loops, best of 3: 371 ms per loop


Share : facebook icon twitter icon
Change table layout from array

Change table layout from array


By : user2703774
Date : March 29 2020, 07:55 AM
To fix the issue you can do I have the following array: , This works for me:
code :
<?
$table = array(
    1 => array('2.1'=>3, '2.2'=>3, '2.3'=>3),
    2 => array('2.1'=>1, '2.2'=>1, '2.3'=>1),
    3 => array('2.1'=>2, '2.2'=>2, '2.3'=>2),
    4 => array('2.1'=>2, '2.2'=>2, '2.3'=>1),
    5 => null,
    6 => null,
    7 => array('2.1'=>2, '2.2'=>2, '2.3'=>2),
    8 => array('2.1'=>2, '2.2'=>2, '2.3'=>2),
    9 => array('2.1'=>2, '2.2'=>2, '2.3'=>2),
    10 => array('2.1'=>1, '2.2'=>1, '2.3'=>1),
    11 => array('2.1'=>3, '2.2'=>1, '2.3'=>1),
    12 => array('2.1'=>1),
    13 => array('2.1'=>5, '2.2'=>3, '2.3'=>2)
);

$checkboxes = array();
foreach($table as $monthtable) {
    foreach($monthtable as $checkbox=>$clicks) {
        if(in_array($checkbox, $checkboxes)) {
            continue;
        }
        else {
            $checkboxes[] = $checkbox;
        }
    }
}

// now we have $checkboxes containing 2.1, 2.2, 2.3, our rows.
?>
<table>
    <tr>
        <th>Month</th>
        <? foreach($table as $month=>$monthtable) {
            echo '<th>'.$month.'</th>';
        } ?>
    </tr>
    <? foreach($checkboxes as $checkbox) {
        echo '<tr>'
            . '<th>'.$checkbox.'</th>';

        // assuming this is still in the same order as the last loop.
        foreach($table as $monthtable) {
            echo '<td>';
            if(array_key_exists($checkbox, $monthtable)) {
                echo $monthtable[$checkbox];
            }
            else {
                echo '0';
            }
            echo '</td>';
        }

        echo '</tr>';
    } ?>
</table>
Linear Layout in side Relative Layout I want to change the color of Relative Layout on Press.

Linear Layout in side Relative Layout I want to change the color of Relative Layout on Press.


By : mjavadi
Date : March 29 2020, 07:55 AM
Any of those help If you are using your layout as part of listview, then why you are giving selector to that layout. You can make use of selector in listview.
Pls try this out. It may sometimes help you:
code :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"   
    android:layout_width="match_parent"
    android:layout_height="70dp"
     >

<RelativeLayout
    android:id="@+id/itemLayoutView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    android:background="@drawable/listview_row_background_selector"
    android:paddingLeft="@dimen/list_view_layout_margin" >

    <LinearLayout
        android:id="@+id/itemLinearLayoutView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="5dp"
        android:clickable="true"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/gameNameView"
            android:layout_width="wrap_content"
            android:layout_height="36dp"
            android:textSize="@dimen/game_list_text_size" />

        <TextView
            android:id="@+id/gameCreationDateView"
            android:layout_width="wrap_content"
            android:layout_height="24dp"
            android:textColor="@color/gray"
            android:textSize="@dimen/small_text_size"
            android:textStyle="italic" />
    </LinearLayout>


</RelativeLayout>
</RelativeLayout>
landscape layout does not change on orientation change and portain layout does not change in orientation change

landscape layout does not change on orientation change and portain layout does not change in orientation change


By : Anju
Date : March 29 2020, 07:55 AM
may help you . Remove android:configChanges="orientation" in your AndroidManifest.xml section for this particular Activity.
Change the layout of listview in custom array adapter

Change the layout of listview in custom array adapter


By : user3495040
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I am learning custom array adapter and i want to do something like if the listview row view is 0(the first row of the listview), i want to have a seperate layout, after that i want another comoon layout for the rest of the list. I have the custom adapter but don't quiet fully understand , how can it be done?. Thank you. , Try something like below:
code :
public View getView(int position, View convertView, ViewGroup Parent){

if(position==0){
  if(convertView == null){
                 LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                 convertView = inflater.inflate(R.layout.first_row_layout,null);

                }
                TextView thisview = (TextView) convertView.findViewById(R.id.email);
                String getListPos = String.valueOf(newsList.getFirstVisiblePosition());
                if(getListPos == "0"){
                    thisview.setText(getListPos);
                }else{
                    thisview.setText(objects.get(position).get(POST_TITLE));
                }

}else{
  if(convertView == null){
                LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                convertView = inflater.inflate(R.layout.otherlayout_view,null);

                }
                TextView thisview = (TextView) convertView.findViewById(R.id.email);
                String getListPos = String.valueOf(newsList.getFirstVisiblePosition());
                if(getListPos == "0"){
                    thisview.setText(getListPos);
                }else{
                    thisview.setText(objects.get(position).get(POST_TITLE));
                }
}



                //thisview.setText(getListPos);

                return convertView;
            }
How to animate active layout change (Layout A -> Layout B) in Android?

How to animate active layout change (Layout A -> Layout B) in Android?


By : Prathmesh Gauri
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I have a problem with animating layout transision in my Android Application. , My code:
MainActivity:
code :
public class MainActivity extends Activity implements View.OnTouchListener {
private ViewFlipper viewFlipper;
private float touchDownX;
private float touchUpX;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    viewFlipper = (ViewFlipper) findViewById(R.id.body_flipper);
    viewFlipper.setOnTouchListener(this);
}

@Override
public boolean onTouch(View v, MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        touchDownX = event.getX();
        return true;
    } else if (event.getAction() == MotionEvent.ACTION_UP) {

        touchUpX = event.getX();

        if (touchUpX - touchDownX > 100) {

            viewFlipper.setInAnimation(AnimationUtils.loadAnimation(this,
                    R.anim.push_right_in));
            viewFlipper.setOutAnimation(AnimationUtils.loadAnimation(this,
                    R.anim.push_right_out));

            viewFlipper.showPrevious();

        } else if (touchDownX - touchUpX > 100) {

            viewFlipper.setInAnimation(AnimationUtils.loadAnimation(this,
                    R.anim.push_left_in));
            viewFlipper.setOutAnimation(AnimationUtils.loadAnimation(this,
                    R.anim.push_left_out));

            viewFlipper.showNext();
        }
        return true;
    }
    return false;
}

}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"     tools:context=".MainActivity">

<ViewFlipper
    android:id="@+id/body_flipper"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#f0f0f0" >

    <include
        android:id="@+id/layout01"
        layout="@layout/page1" />
    <include
        android:id="@+id/layout02"
        layout="@layout/page2" />
    <include
        android:id="@+id/layout02"
        layout="@layout/page3" />

</ViewFlipper>

</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
    android:duration="400"
    android:fromXDelta="-100.0%p"
    android:toXDelta="0.0" />
<alpha
    android:duration="400"
    android:fromAlpha="0.1"
    android:toAlpha="1.0" />
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate
    android:duration="400"
    android:fromXDelta="0.0"
    android:toXDelta="100.0%p" />
<alpha
    android:duration="400"
    android:fromAlpha="1.0"
    android:toAlpha="0.1" />
</set>
Related Posts Related Posts :
  • What are the centroid of k-means clusters with PCA decomposition?
  • How do mongoengine filter field not null?
  • Categorize results based on Model in haystack?
  • Error installing pycrypto on my mac
  • Can Django ORM has strip field?
  • Python pack / unpack converts to Objective C
  • Python - Selenium Locate elements by href
  • Couldn't iterate over a dictionary context variable in template, despite having all in place, as far as I know?
  • Test if Django ModelForm has instance on customized model
  • Reading excel column 1 into Python dictionary key, column 2 into value
  • AttributeError: 'module' object has no attribute 'timeit' while doing timeit a python function
  • Accessing button using selenium in Python
  • Removing White Spaces in a Python String
  • Sort timestamp in python dictionary
  • How to use Python 2 packages in Python 3 project?
  • retrieve links from web page using python and BeautifulSoup than select 3 link and run it 4 times
  • applying lambda to tz-aware timestamp
  • Having two Generic ListViews on the same page
  • Merging numpy array elements using join() in python
  • pythonic way to parse/split URLs in a pandas dataframe
  • Added iterating over page id in Scrapy, responses in parse method no longer run
  • wanting to add an age gate to my quiz
  • Removing top empty line when writing a text file Python
  • How to use a template html in different folder on Google App Engine python?
  • Access ndarray using list
  • unable to post file+data using python-requests
  • How to test aws lambda functions locally
  • inconsistent plot between matplotlib and seaborn in Python
  • How matplotlib show obvious changes?
  • Project in Python3, reading files, word data
  • Check for specific Item in list without Iteration or find()
  • Unicode encoding when reading from text file
  • Overloaded variables in python for loops?
  • All elements have same value after appending new element
  • Python Threading loop
  • `_pickle.UnpicklingError: the STRING opcode argument must be quoted`
  • Python: How to stop a variable from exceeding a value?
  • python textblob and text classification
  • Django - Context dictionary for attribute inside a class
  • Database is not updated in Celery task with Flask and SQLAlchemy
  • Shapely intersections vs shapely relationships - inexact?
  • How to extract a percentage column from a periodic column and the sum of the column?
  • Zombie ssh process using python subprocess.Popen
  • Python regex to capture a comma-delimited list of items
  • joining string and long in python
  • Value Error in python numpy
  • Check if any character of a string is uppercase Python
  • TensorFlow - why doesn't this sofmax regression learn anything?
  • Python Anaconda Proxy Setup via .condarc file on Windows
  • Creating django objects from emails
  • Get spotify currently playing track
  • Select multiple columns and remove values according to a list
  • Python - How to Subtract a Variable By 1 Every Second?
  • Tkinter unable to alloc 71867 bytes
  • How to add Variable to JSON Python Django
  • CSRF token missing or invalid Django
  • Python: writing to a text file
  • Extracting multiple rows from pandas dataframe and converting to columns
  • Pinging a remote PC with Flask, causing server to block
  • Making a fractal graph using a 2D array?
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co